Results 1 to 9 of 9

Thread: How to detect when a QDialog is clicked anywhere?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to detect when a QDialog is clicked anywhere?

    What's about using QWidget::mousePressEvent() and close the widget there?

  2. #2
    Join Date
    Feb 2011
    Posts
    7
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to detect when a QDialog is clicked anywhere?

    We have tried QWidget::mousePressEvent(), but It not works. This PopUp contains inside others QWidgets like QLabel, QGroupBox,... If the users click the PopUp in a area with no others QWidgets mousePressEvent works, but if the user click for example on QGroupBox widget then the mousePressEvent is not thrown.

  3. #3
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: How to detect when a QDialog is clicked anywhere?

    Try to install event filter on every widget in the dialog:
    Qt Code:
    1. MyDialog * dialog = new MyDialog();
    2. // for each element in the window:
    3. label->installEventFilter(dialog);
    4. groupBox->installEventFilter(dialog);
    5. // ...
    6.  
    7. bool MyDialog::eventFilter(QObject *obj, QEvent *event){
    8. if (event->type() == QEvent::MouseButtonPress) {
    9. this->close();
    10. return true;
    11. } else {
    12. return false;
    13. }
    14. }
    To copy to clipboard, switch view to plain text mode 
    This code is not tested by me, I'm just wondering.
    Last edited by stampede; 3rd March 2011 at 08:56. Reason: updated contents (link)

Similar Threads

  1. Replies: 9
    Last Post: 25th March 2011, 21:22
  2. QDialog.exec() exiting without calling QDialog::accept()
    By doggrant in forum Qt Programming
    Replies: 3
    Last Post: 2nd February 2011, 11:35
  3. Replies: 5
    Last Post: 23rd October 2010, 14:17
  4. closing a Qdialog called from a Qdialog
    By OverTheOCean in forum Qt Programming
    Replies: 3
    Last Post: 28th September 2009, 08:02
  5. Detect which OS?
    By December in forum Qt Programming
    Replies: 6
    Last Post: 24th May 2007, 23:01

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
  •  
Qt is a trademark of The Qt Company.