Results 1 to 4 of 4

Thread: Modal Dialog requires 2 clicks of ok to close, Modeless only 1

  1. #1
    Join Date
    Oct 2017
    Posts
    2
    Qt products
    Qt5

    Default Modal Dialog requires 2 clicks of ok to close, Modeless only 1

    Linux Touchscreen Device.
    [1] Creating simple MessageBox (0k button) using exec() requires 2 clicks to close
    [2] Creating one with msgBox->setWindowModality(Qt::NonModal); msgBox->Show() requires just 1 click.
    If do not call msgBox->setWindowModality(Qt::NonModal); in [2] then need 2 clicks.
    So seems if window is modal need 2 clicks.
    Any ideas what could cause this? The message box itself is being created as result of push button click

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Modal Dialog requires 2 clicks of ok to close, Modeless only 1

    Any ideas what could cause this?
    Not without seeing the code you use to create and show the message box, as well as the slot and code you use to connect to the push button signals.

    Please read my signature (below) on how to post code.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Oct 2017
    Posts
    2
    Qt products
    Qt5

    Default Re: Modal Dialog requires 2 clicks of ok to close, Modeless only 1

    The 2-click issue disappears if I use clicked() for the pb connection instead of pressed() ... debug tells me that the pressed signal is NOT being emitted twice though, so no idea why using pressed() would have this side-effect. The reason I was using QPushButton:ressed instead ofQPushButton::clicked was because the "clicked" was not responsive, as though focus was being lost between the pressed and release actions.

    Qt Code:
    1. //This called in MainWindow::Init() function
    2. // If use QPushButton::pressed then 2 clicks required to close window
    3. // If use QPushButton::clicked then the pb itself is not responsive
    4.  
    5. bConnected = connect(ui->pB_VerDlg, &QPushButton::pressed,this, &MainWindow::ShowVersionBox);
    6. if (!bConnected) printf("failed to connect clicked() to ShowVersionBox()\n");
    7.  
    8. ---
    9.  
    10. void MainWindow::ShowVersionBox() {
    11. QMessageBox msgBox;
    12.  
    13. printf("======> Handling PB click\n");
    14.  
    15. msgBox.setWindowTitle("");
    16. msgBox.setText("Applications List");
    17. msgBox.setFont(fontBold);
    18. msgBox.setStyleSheet(QString::fromUtf8("background-color: rgb(0, 75, 141); color: white; "));
    19.  
    20. msgBox.setStandardButtons(QMessageBox::Ok);
    21. msgBox.button(QMessageBox::Ok)->setFont(fontBold);
    22. msgBox.button(QMessageBox::Ok)->setMinimumSize(QSize(70*HMI_SCALE, 40*HMI_SCALE));
    23. msgBox.setInformativeText("All info");
    24.  
    25. // Close box after 30s if left open
    26. QTimer::singleShot(CLOSE_WINDOW_MS, &msgBox, SLOT(close()));
    27.  
    28. msgBox.exec() ;
    29. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Modal Dialog requires 2 clicks of ok to close, Modeless only 1

    The connect() call in your MainWindow::Init() method has nothing to do with closing the message box, it concerns when the slot that creates and posts the message box is invoked.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 3
    Last Post: 8th August 2016, 14:20
  2. Modal dialog only modal to base window?
    By SvenA in forum Qt Programming
    Replies: 3
    Last Post: 10th April 2015, 10:25
  3. Replies: 17
    Last Post: 2nd June 2009, 11:18
  4. Replies: 3
    Last Post: 1st February 2009, 16:49
  5. Qt Modal/Modeless possible bug in MS Windows
    By Daliphant in forum Qt Programming
    Replies: 1
    Last Post: 11th June 2008, 18:41

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.