Results 1 to 9 of 9

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

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

    Default How to detect when a QDialog is clicked anywhere?

    Hello,

    I would like to know if there is a way to dectect when user clicks anywhere in a QDialog.

    We are using a QDialog to show a popup to the user, we would like that if user clicks the popup anywhere this hides. To detect if the user clicks the QDialog anywhere we have try it reimplementing mousePressEvent, but the problem is if the user click in a GroupBox that it's inside the QDialog or an Image, then we don't receive the mousePressEvent. It seems that the mousePressEvent only is thrown if the user clicks the region of QDialog with no widgets.

    Thanks

  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: How to detect when a QDialog is clicked anywhere?

    You mean you want a QSplashScreen ?
    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. #3
    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?

    No, We don't want a QSplashScreen, what we need is a PopUp to notify to user that request to retrieve some files has been received, We have implemented it with a QDialog. Ten seconds after appearing it hides automatically, but we would like that the user can click Popup anywhere to hide it if is disturbing, before the 10 seconds.

  4. #4
    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?

  5. #5
    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.

  6. #6
    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 09:56. Reason: updated contents (link)

  7. #7
    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: How to detect when a QDialog is clicked anywhere?

    Quote Originally Posted by MarcCals View Post
    No, We don't want a QSplashScreen, what we need is a PopUp to notify to user that request to retrieve some files has been received, We have implemented it with a QDialog. Ten seconds after appearing it hides automatically, but we would like that the user can click Popup anywhere to hide it if is disturbing, before the 10 seconds.
    If you want a popup, then why don't you use Qt::Popup window flag with a regular widget?
    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.


  8. #8
    Join Date
    Nov 2010
    Posts
    315
    Thanked 53 Times in 51 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

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

    I would try QWidget::grabMouse.

  9. #9
    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?

    Using QWidget::grabMouse, It doesnt works because then no other widget except the PopUp receive mouseEvent. If you have another dialogs o widgets showed, they not receive mouseEvents.

    Finally I have implemented it installing even widget to all widget ins the PopUp.

    Thanks to all for your help,

Similar Threads

  1. Replies: 9
    Last Post: 25th March 2011, 22:22
  2. QDialog.exec() exiting without calling QDialog::accept()
    By doggrant in forum Qt Programming
    Replies: 3
    Last Post: 2nd February 2011, 12:35
  3. Replies: 5
    Last Post: 23rd October 2010, 15:17
  4. closing a Qdialog called from a Qdialog
    By OverTheOCean in forum Qt Programming
    Replies: 3
    Last Post: 28th September 2009, 09:02
  5. Detect which OS?
    By December in forum Qt Programming
    Replies: 6
    Last Post: 25th May 2007, 00: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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.