PDA

View Full Version : clicked signal from QMainWindow



Tomasz
13th December 2010, 13:26
Hello!

I want to do something like this: clicking on 'lock' button should lock the screen (disable all objects), and clicking anywhere on QMainWindow should do some actions, and then unlock the window. Since there is not such a thing like clicked signal emitted from QMainWindow I'm wondering how can I check if the window was clicked while 'lock' state.

thanks in advance
best regards
Tomasz

high_flyer
13th December 2010, 13:35
Since there is not such a thing like clicked signal emitted from QMainWindow I'm wondering how can I check if the window was clicked while 'lock' state.


see mousePressEvent().

Tomasz
13th December 2010, 14:03
Thanks! I've reimplemented this function:



void MainWindow::mousePressEvent(QMouseEvent *event)
{
QTextStream out(stdout);

if(event->button()==Qt::LeftButton)
{
out << "test" << endl;
}

}


And it works just fine. One more question. When I've reimplemented it, it will be working all the time that way. Can I make it work this way only in my 'lock' mode? I think I can use some variable to detect that mode, but is this the only way?

thanks in advance
best regards
Tomasz

high_flyer
13th December 2010, 14:12
I am not quite sure I understand your last question.
One way you could go about it, is just emit a signal in your mousePressEvent(), and in the slot you can have the logic for doing things depending on your mode, as you wanted in your original question.
But that is only a semantic difference.
You can just as well do that in the mousePressEVent().

P.S
Instead of using QTextStream for debug messages you can use qDebug().