PDA

View Full Version : Making a mouse click event close the window



Momergil
17th February 2013, 15:42
Hello!

In my software, in a given time, a pop-up window needs to be shown in order to send a message:



QDialog *warningWindow = new QDialog(this);
warningWindow->resize(200,100);
warningWindow->setWindowTitle("Alarm!");
warningWindow->setWindowFlags(Qt::Popup | Qt::WindowStaysOnTopHint);
warningWindow->setWindowState(Qt::WindowActive);

QLabel *alarm_titulo = new QLabel("TIMETOUT!",warningWindow);
alarm_titulo->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
alarm_titulo->resize(warningWindow->size());
alarm_titulo->show();

QFont font;
font.setPointSize(20);
alarm_titulo->setFont(font);

warningWindow->exec();

SAFEDELETE(warningWindow);


As you can see, I want to make it a Popup style dialog (i.e. a dialog but without the typical window borders with the close button etc.). Since it will have no buttons to close it, I want warningWindow to close when the user clicks on it (or in its label alarm, which compress all of warningWindow's area). I know this has something to do with the mouseClickEvent, but once again I'm having trouble using this event handler thing from Qt (in my opinion mouse handling is still one of the worst things in Qt: everything could be much easier with simple signals!). How can I connect this click event with warningWindow's close() slot?


Thanks,

Momergil

wysota
17th February 2013, 18:27
QSplashScreen

anda_skoa
17th February 2013, 19:58
Or a QMenu with a QWidgetAction

But mouse handling is also trivial. Simply derive from the widget you want to have mouse handling on and implement the appropriate mouse event handler methods.
Or do it more hackish and use an event filter on an unchanged class.

Still, I would try wysota's and my suggestions first ;)

Cheers,
_