Results 1 to 8 of 8

Thread: Modal dialog not behaving

  1. #1
    Join Date
    Oct 2006
    Location
    Hawaii
    Posts
    130
    Thanks
    48
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Modal dialog not behaving

    I recently upgraded to Qt 4.4.1, and after compiling my program and running it, I noticed that when the first modal dialog, a login popup appears, it does not allow me to click on any of the buttons in it anymore. In addition, I can not drag the login popup around like I normally should be able to. I broke down the code to a simple example, and the same exact thing happens: the dialog will appear, but I can not click on any of the buttons or fields in it. Here is the code for the simple example that has this problem:

    Main.cpp:
    Qt Code:
    1. #include <QApplication>
    2.  
    3. #include "calculatorform.h"
    4.  
    5.  
    6. int main(int argc, char *argv[]) {
    7. QApplication app(argc, argv);
    8.  
    9. //show the main window:
    10. FabwareMain calculator;
    11. calculator.show();
    12. return app.exec();
    13. }
    To copy to clipboard, switch view to plain text mode 
    Calculatorform.h:
    Qt Code:
    1. #ifndef CALCULATORFORM_H
    2. #define CALCULATORFORM_H
    3. //user interface for this window:
    4. #include "ui_calculatorform.h"
    5.  
    6. //dialogs that are spawned from this window:
    7. #include "dialog_login.h"
    8.  
    9. #include "var_login.h"
    10.  
    11. //QT modules used by this window:
    12. #include <QString>
    13.  
    14. class FabwareMain : public QMainWindow {
    15. Q_OBJECT
    16.  
    17. public:
    18. FabwareMain();
    19.  
    20. private slots:
    21.  
    22. void popupLogin();
    23.  
    24. private:
    25. //interface:
    26. Ui::FabwareMain ui;
    27.  
    28. //variables:
    29. var_login login; //stores last login information
    30. };
    31.  
    32. #endif
    To copy to clipboard, switch view to plain text mode 

    Calculatorform.cpp:
    Qt Code:
    1. #include <QtGui>
    2.  
    3. #include "calculatorform.h"
    4. #include <QMessageBox>
    5. #include <QDebug>
    6. /*
    7. Constructor for main window:
    8. */
    9. FabwareMain::FabwareMain() {
    10. ui.setupUi(this);
    11.  
    12. connect( ui.actionLogin, SIGNAL( triggered() ), this, SLOT( popupLogin() ) );
    13.  
    14. }
    15.  
    16. //popup for login dialog:
    17. void FabwareMain::popupLogin() {
    18.  
    19. //create a dialog box:
    20. DialogLogin dlg(this);
    21.  
    22. //do something once we click OK:
    23. if( dlg.exec() == QDialog::Accepted ) {
    24. login = dlg.login;
    25.  
    26.  
    27. }
    28. }
    To copy to clipboard, switch view to plain text mode 

    Dialog_login.h
    Qt Code:
    1. #ifndef DIALOG_LOGIN_H
    2. #define DIALOG_LOGIN_H
    3.  
    4. //user interface items:
    5. #include "ui_dialog_login.h"
    6.  
    7. //data structure items:
    8. #include "var_login.h"
    9.  
    10. class DialogLogin : public QDialog, private Ui::DialogLogin {
    11.  
    12. Q_OBJECT
    13.  
    14. public:
    15. //functions:
    16. DialogLogin(QWidget *parent = 0);
    17.  
    18.  
    19. //variables:
    20. var_login login;
    21.  
    22. private slots:
    23. void returnVars();
    24.  
    25. private:
    26.  
    27. };
    28.  
    29. #endif
    To copy to clipboard, switch view to plain text mode 

    dialog_login.cpp:
    Qt Code:
    1. #include <QtGui>
    2.  
    3. #include "dialog_login.h"
    4.  
    5. //setup interface of main window:
    6. DialogLogin::DialogLogin(QWidget *parent) : QDialog(parent) {
    7.  
    8. setupUi(this);
    9.  
    10. //connect form item signals to slots that arent in the UI file here:
    11. connect(buttonBox, SIGNAL(accepted()), this, SLOT(returnVars()));
    12. connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
    13.  
    14. }
    15.  
    16. void DialogLogin::returnVars() {
    17.  
    18. login.username = userid->text();
    19. login.password = password->text();
    20. accept();
    21. }
    To copy to clipboard, switch view to plain text mode 

    var_login.h:
    Qt Code:
    1. #ifndef VAR_LOGIN_H
    2. #define VAR_LOGIN_H
    3.  
    4. #include <QString>
    5.  
    6. class var_login {
    7.  
    8. public:
    9. QString username,
    10. password;
    11.  
    12. };
    13.  
    14. #endif
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Modal dialog not behaving

    where is ui file?
    PS. please, post compilable sources in archive, I spent time for creating files etc....

  3. #3
    Join Date
    Oct 2006
    Location
    Hawaii
    Posts
    130
    Thanks
    48
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Modal dialog not behaving

    Here you go, the same code and the pro files in a zip
    Attached Files Attached Files

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Modal dialog not behaving

    Works fine for me on X11 with both Qt 4.4.0 and Qt 4.5.0-snapshot.
    J-P Nurmi

  5. #5
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Modal dialog not behaving

    I found trouble, the trouble in dialog_login.ui,
    QLineEdit userid has windowModality property Qt::ApplicationModal.
    If you set it in Qt::NonModal, everything works fine.

  6. The following user says thank you to spirit for this useful post:

    tpf80 (19th August 2008)

  7. #6
    Join Date
    Oct 2006
    Location
    Hawaii
    Posts
    130
    Thanks
    48
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Modal dialog not behaving

    Yes, this fixed the issue. Thank you for your help

    What is interesting, is that this ui file was made in designer, and I did not see the "windowModality" property in designer for the QLineEdit, so I am not sure how it got there especially since this property for the main widget was Qt::NonModal. Editing the ui file by hand did work though.

  8. #7
    Join Date
    May 2008
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Modal dialog not behaving

    I'm a Qt n00b who inherited the duty to maintain a data entry application written in an earlier version of Qt. I've just started going through the code, learning the application and the Qt environment.

    I had the same problem with a QDialog object that you mentioned in your post that started this thread.

    My QDialog object contains:

    (1) a QTableView to list some records in a query from which the user was to choose one by clicking on it.

    (2) an OK QPushButton to accept the choice, and pass the record ID selected to the parent window while closing the QDialog window.

    (3) a Cancel QPushButton to close the QDialog window.

    Originally, the WindowModality properties of the QDialog window object and (1) and (3) were set to "NonModal" and that of (2) was set to "Aplication Modal".

    The QDialog functioned perfectly well when compiled in an earlier version of Qt. But when I compiled it in version 4.4.0, the behavior was exactly as you described.

    After I read this thread, I changed the WindowModality property of (2) to "NonModal" to match the WindowModality properties of the QDialog window object and (1) and (3), thinking that the inconstant values of the object properties were causing the problem.

    And it worked!

    Obviously, some "under the hood" functionality of the Qt libraries changed, causing the QDialog window object to behave differently when compiled with the new version even though there were no code or ui changes.

    But what puzzles me is that even though the QDialog window object and all the objects it contains now have their WindowModality properties set to "NonModal", the QDialog window still behaves like it is a modal window; that is, you can't shift focus to the parent window without first closing the QDialog child window. This is fine, since that is how it is supposed to function. But by my understanding, if the QDialog is set to be "NonModal", then it shouldn't behave like a modal window, should it?

    Is there something that I don't understand or is this a bug?

  9. #8
    Join Date
    Oct 2006
    Location
    Hawaii
    Posts
    130
    Thanks
    48
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Modal dialog not behaving

    In my case what seemed to be happening, was that when i use "exec()" then the pop up of course is shown modal. The "Qt::ApplicationModal" property of the QLineEdit caused it to be modal relative to the pop up and blocking all input to the pop up, which in turn blocked the main window, locking up the whole program.

    Thus, making the QLineEdit Qt::NonModal made it not block the pop up window, in turn allowing the submit button to work.

    This behavior makes sense, however in older versions (and on other operating systems aside from windows) the "Qt::ApplicationModal" property in the .ui file seems to be ignored for the QLineEdit, as I had used the offending .ui file for quite a while on many platforms with no problem.

    I am not even sure how my QLineEdit got this property given that I made the UI file with designer, and designer does not give you the option to set this property for QLineEdit. It was however originally made with an older designer in the 4.x series on linux, and then used when I compiled with the latest version on windows. Manually editing the .ui file to remove that property fixed the issue right away.

Similar Threads

  1. modal dialog blocking problem...
    By photonmaster in forum Qt Programming
    Replies: 3
    Last Post: 4th June 2008, 09:49
  2. Special Modal Dialog
    By adonel in forum Qt Programming
    Replies: 2
    Last Post: 13th May 2008, 08:12
  3. System modal dialog!!
    By boss_bhat in forum Qt Programming
    Replies: 2
    Last Post: 23rd June 2006, 07:01
  4. QDialog::exec() cereates no modal dialog
    By sboesch in forum Qt Programming
    Replies: 8
    Last Post: 27th March 2006, 17:03
  5. dialog box
    By Bahar in forum Qt Programming
    Replies: 3
    Last Post: 31st January 2006, 14:52

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.