Results 1 to 3 of 3

Thread: Making a mouse click event close the window

  1. #1
    Join Date
    Jun 2011
    Location
    Porto Alegre, Brazil
    Posts
    482
    Thanks
    165
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Making a mouse click event close the window

    Hello!

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

    Qt Code:
    1. QDialog *warningWindow = new QDialog(this);
    2. warningWindow->resize(200,100);
    3. warningWindow->setWindowTitle("Alarm!");
    4. warningWindow->setWindowFlags(Qt::Popup | Qt::WindowStaysOnTopHint);
    5. warningWindow->setWindowState(Qt::WindowActive);
    6.  
    7. QLabel *alarm_titulo = new QLabel("TIMETOUT!",warningWindow);
    8. alarm_titulo->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
    9. alarm_titulo->resize(warningWindow->size());
    10. alarm_titulo->show();
    11.  
    12. QFont font;
    13. font.setPointSize(20);
    14. alarm_titulo->setFont(font);
    15.  
    16. warningWindow->exec();
    17.  
    18. SAFEDELETE(warningWindow);
    To copy to clipboard, switch view to plain text mode 

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Making a mouse click event close the window

    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    Momergil (19th February 2013)

  4. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Making a mouse click event close the window

    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,
    _

  5. The following user says thank you to anda_skoa for this useful post:

    Momergil (19th February 2013)

Similar Threads

  1. Replies: 11
    Last Post: 15th July 2008, 13:11
  2. close window when click on a label
    By sabeesh in forum Qt Programming
    Replies: 3
    Last Post: 29th October 2007, 07:35
  3. Mouse click event problem
    By impeteperry in forum Qt Programming
    Replies: 3
    Last Post: 4th April 2007, 13:44
  4. The event fired by the mouse click on the frame
    By Placido Currò in forum Qt Programming
    Replies: 8
    Last Post: 3rd March 2007, 09:05
  5. mouse click event
    By vijay anandh in forum Qt Programming
    Replies: 1
    Last Post: 1st May 2006, 09:24

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.