Results 1 to 10 of 10

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

Hybrid View

Previous Post Previous Post   Next Post Next Post
  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.

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.