[PyQt] Where to start

diego diego at cortassa.net
Fri Jun 3 15:24:55 BST 2011

>> I am trying to do is display an image, and then using drag-selection 
>> to
>> select a sub-image for later processing. Eventually I want to be 
>> able
>> to select multiple regions and tag each region for appropruate back 
>> end
>> processing, but for now just being able to select one sub-image 
>> would
>> be good. I can display an image, but don't know how to implement
>> drag-selection (think it is also know as rubber band selection). I 
>> am
>> assuming I will need to write some mouse-callbacks or something. My
>> search-fu has failed me and I haven't been able to find any examples 
>> to
>> study. Can someone give me any pointers to which widgets I should be
>> using and perhaps where to find a sample program I can study.
> There didn't seem to be much in the PyQt examples to show this - the
> itemviews/chart example does use QRubberBand to allow the user to 
> select
> data, but that's not the best example to learn this technique from.
> I quickly wrote an example that does part of what you want:
> http://www.diotavelli.net/PyQtWiki/Selecting_a_region_of_a_widget [1]
> Hope this helps,

Hi David,
thanks for your example! I was experimeting on QRubberBand too and it 
helped me a lot.

I tried your code myself but I found a small bug that confused me at 
start, in:

def mouseMoveEvent(self, event):

         if event.button() == Qt.LeftButton:

you check if the value retured by QMouseEvent.button() is Qt.LeftButton 
but in 
states that "the returned value is always Qt.NoButton for mouse move 
events."; the code in mouseMoveEvent will never be executed and the 
rubber band will not work.

Diego Cortassa

Il messaggio e' stato analizzato alla ricerca di virus o
contenuti pericolosi da MailScanner, ed e'
risultato non infetto.

More information about the PyQt mailing list