Results 1 to 10 of 10

Thread: how to make the pop up widget as modal ?

  1. #1
    Join Date
    Oct 2010
    Posts
    12
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Question how to make the pop up widget as modal ?

    Hello, I use these code to create a pop up widget and set it modal
    QWidget* popUp = new QWidget(this, Qt::Popup);
    popUp->setWindowModality(Qt::WindowModal);
    QRect rect = QStyle::alignedRect(layoutDirection(), Qt::AlignBottom, QSize(width(), height()/3), geometry());
    popUp->setGeometry(rect);
    popUp->show();
    however, after the pop up widget show, I click the place that outside the pop up widget but in the background widget, the pop up widget disappear.
    So what should I do to set the pop up widget modal ?

  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: how to make the pop up widget as modal ?

    From the docs:
    This property only makes sense for windows.
    A window is a widget that isn't visually the child of any other widget and that usually has a frame and a window title.
    Why don't you use a QDialog?
    ==========================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
    Oct 2010
    Posts
    12
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: how to make the pop up widget as modal ?

    thanks for quick reply.
    So can the dialog show as pop up ?

  4. #4
    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: how to make the pop up widget as modal ?

    yes, read the docs!
    Call QDialog::exec() to show it as modal.
    ==========================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.

  5. #5
    Join Date
    Oct 2010
    Posts
    12
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: how to make the pop up widget as modal ?

    if I use this code
    QDialog* popUp = new QDialog(this, Qt::Popup);
    ...
    popUp.exec();
    it remains the same as the QWidget.
    And If I use this code
    QDialog* popUp = new QDialog(this);
    ...
    popUp.exec()
    it becomes modal, but it not like a pop up widget
    it is full screen.
    Both of them were not what I want.

  6. #6
    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: how to make the pop up widget as modal ?

    it remains the same as the QWidget.
    Hmm...
    try explicitly setting modality setModal(true);

    I would expect it to be modal, and based on the docs, it should be.

    If its not, it might be a Qt bug - but maybe some one else can comment on this.
    ==========================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.

  7. #7
    Join Date
    Oct 2010
    Posts
    12
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: how to make the pop up widget as modal ?

    I just want to have a pop widget like the widget that "show open applications" after click options on the device. So any one has done this, please give me some suggests.
    Any reply will be appreciate.
    Last edited by kongkong163; 10th January 2011 at 11:33.

  8. #8
    Join Date
    Feb 2011
    Posts
    2
    Qt products
    Qt4
    Platforms
    Symbian S60 Maemo/MeeGo

    Default Re: how to make the pop up widget as modal ?

    Hi,
    maybe i know what you would.

    If it's not late:

    QDialog *yourDialog= new QDialog(this, Qt::Popup | Qt:: Dialog);

    // create your dialog ....

    yourDialog->exec();


    It works for me like a dialog without the title bar at the top, and without buttons at the bottom and you can click outside the dialog window, it won't disappear.
    I hope i could help
    Last edited by Dawhun; 19th March 2011 at 09:45.

  9. #9
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to make the pop up widget as modal ?

    You could as well simply use FramelessWindowHint / StayOnTop with any QWidget. This will make ur widget stay and also wont hide like popups.

  10. #10
    Join Date
    Feb 2011
    Posts
    2
    Qt products
    Qt4
    Platforms
    Symbian S60 Maemo/MeeGo

    Default Re: how to make the pop up widget as modal ?

    Or you can say a QWidget to work as a QDialog

    QWidget *yourWidget = new QWidget(this, Qt::Popup | Qt:: Dialog);

    //create your widget ....

    yourWidget ->setWindowModality(Qt::WindowModal);
    yourWidget ->show();

    That's it.

Similar Threads

  1. How to make modal widget wait for input after it is shown.
    By cuiqimeng in forum Qt Programming
    Replies: 4
    Last Post: 17th December 2010, 06:12
  2. How to make window semi modal
    By kaushal_gaurav in forum Qt Programming
    Replies: 7
    Last Post: 29th August 2008, 08:27
  3. Close Button on Modal Widget?
    By vishal.chauhan in forum Qt Programming
    Replies: 5
    Last Post: 18th February 2008, 11:38
  4. setting widget as modal, disables button
    By munna in forum Qt Programming
    Replies: 3
    Last Post: 27th November 2006, 09:49
  5. cannot make a main window modal
    By Dark_Tower in forum Qt Programming
    Replies: 12
    Last Post: 23rd March 2006, 10:21

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.