I'm implementing a simple "window" that should display a bitmap picture with Qt 4.7 / 4.6 (I've got a Fedora 14 32 bits machine and a Mandriva 2010.2 64 bits machine). I've created a class called BlackBoard that inhertits from QWidget, that has at the moment a "Close" button and another QWidget class called Screen. Screen is just a pixel field that displays a QImage.
I need a method BlackBoard::waitForClick() that waits for the user to click on the picture (i.e on the Screen widget), and then send the (x-y) coordinates (i.e. the clicked pixel from the picture).
I implemented Screen::mousePressEvent, that allows me to get the coordinates in the Screen class. I emit a signal from Screen::mousePressEvent, which is "caught" by a dedicated slot in my BlackBoard class.
The way BlackBoard::waitForClick is implemented is this :
@void BlackBoard::waitForClick( unsigned & x, unsigned & y )
qApp -> exec()
// Get the coordinates from the dedicated Screen method
child -> coordinates( x, y );
while ( /* ! child was clicked, detected by Screen sending a signal to a BlackBoard slot */ );
and the 2 coordinates are retrieved.
My main.cpp looks like this :
BlackBoard board( 800, 600, 0xFFFFFF );
unsigned coordX, coordY;
board.waitForClick( coordX, coordY );
cout << coordX << coordY << endl;@
The problem I have is that I can click as many time as I want, is always waits for me to close the widget to quit waitForClick. Is there a way to quit the method and get the coordinates as soon as a click on the Screen widget is made?
I may agree on basically any changes in the core implementation, however the interface should be
create the BlackBoard object
access / modify pixels of the Screen owned by the Blackboard object
use waitForClick to select a pixel
and the window should always be on seen and be prone to be real-time modified. I want it to disappear only when the application is closed, not the other way around.
I tried to look for this in various forums, in Qt documentation, but didn't find anything. I'm thus wondering if there is a way to do this...
Can anybody help?