Results 1 to 9 of 9

Thread: Creating modal dialogs

  1. #1
    Join Date
    Jan 2010
    Posts
    190
    Thanks
    18
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Creating modal dialogs

    Hi! I created a subclass of a QDialog to create a custom one. I inherited QDialog and built it with Qt:ialog window flag. After that, before using exec(), I set window modality to ApplicationModal. However, I still get that the dialog stays on top and the rest of the application which is in the background is still usable. What can there be wrong? I can't find in the documentation anything I'm missing.

    Thanks!

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Creating modal dialogs

    I inherited QDialog and built it with Qt:ialog window flag
    You don't have to do that if you inherit QDialog, since it is already set by QDialog.

    What can there be wrong?
    Hmm.. can you show your code?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Jan 2010
    Posts
    190
    Thanks
    18
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Creating modal dialogs

    [Sorry, made a mistake, submitted twice]

  4. #4
    Join Date
    Jan 2010
    Posts
    190
    Thanks
    18
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Creating modal dialogs

    This is how I build the class:

    Qt Code:
    1. CustomMessageBox customMessageBox(..., parent, Qt::Dialog);
    2. customMessageBox.setWindowModality(Qt::ApplicationModal);
    3. customMessageBox.exec();
    To copy to clipboard, switch view to plain text mode 

    and the constructor is:

    Qt Code:
    1. CustomMessageBox::CustomMessageBox(..., QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f) {
    2. this->resize(...);
    3. this->move(...);
    4. this->setWindowFlags(Qt::FramelessWindowHint);
    5. this->setAttribute(Qt::WA_TranslucentBackground, true);
    6. // ...
    7. }
    To copy to clipboard, switch view to plain text mode 

    The ... stands for some other instructions, such as creating some buttons, pixmaps etc...
    The class inherits QDialog, I defined it as:

    Qt Code:
    1. class CustomMessageBox : public QDialog {
    2. // ...
    3. }
    To copy to clipboard, switch view to plain text mode 

    Any idea what I'm doing wrong? (I'm working under Windows CE)
    Thanks!

  5. #5
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Creating modal dialogs

    Try running this on another system which is not CE, and see if it behaves the same...
    I see nothing in the code you posted that should not allow it to be application modal.
    Another possibility is that the frame-less flag somehow interferes.
    Try it with normal window decorations, and see if it behaves the same.
    Try also with out the WA_TranslucentBackground property.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  6. #6
    Join Date
    Mar 2009
    Location
    Tennessee, US
    Posts
    41
    Thanks
    3
    Thanked 11 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Creating modal dialogs

    Quote Originally Posted by Luc4 View Post
    This is how I build the class:

    Qt Code:
    1. CustomMessageBox customMessageBox(..., parent, Qt::Dialog);
    2. customMessageBox.setWindowModality(Qt::ApplicationModal);
    3. customMessageBox.exec();
    To copy to clipboard, switch view to plain text mode 
    One of the issues might be that calling the exec() function changes the modality of the window to Qt::WindowModal. If you want to make it ApplicationModel, then simply replace exec() with show().

  7. #7
    Join Date
    Mar 2010
    Location
    Kawasaki, Japan
    Posts
    13
    Qt products
    Qt/Embedded Qt Jambi
    Platforms
    Symbian S60

    Default Re: Creating modal dialogs

    Luc,

    Please specify what is the operation you are able to do on the application behind the dialog...
    Is it touch event or the key event?

    If key event, then it could be a chance that the event is not being consumed by the top most widget, thus the event propogates to the widgets in the lower levels...

    Please clarify

    -Girish

  8. #8
    Join Date
    Jan 2010
    Posts
    190
    Thanks
    18
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Creating modal dialogs

    The behavior I'm seeing is that the window is always on top, but the window below is active, which means it reacts to clicks.
    I made some tests and it seems that setting the parent to NULL and removing Qt::FramelessWindowHint make it work correctly. Is this the expected behavior?
    Thanks for your help!

  9. #9
    Join Date
    Jan 2010
    Posts
    190
    Thanks
    18
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Creating modal dialogs

    Unfortunately I need Qt::FramelessWindowHint and I need to set the parent (otherwise I wouldn't have transparency). Any solution?

Similar Threads

  1. Testing modal dialogs with QTestLib
    By bitflyer in forum Qt Programming
    Replies: 1
    Last Post: 31st May 2013, 15:34
  2. Replies: 3
    Last Post: 17th December 2010, 02:06
  3. QT Modal Dialog
    By jiapei100 in forum Qt Programming
    Replies: 1
    Last Post: 16th January 2010, 17:15
  4. Bug with modal windows on Mac? [Qt 3.3]
    By kalos80 in forum Qt Programming
    Replies: 0
    Last Post: 15th February 2008, 16:52
  5. screen number and modal dialogs
    By high_flyer in forum Qt Programming
    Replies: 18
    Last Post: 22nd June 2007, 18:48

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.