Results 1 to 6 of 6

Thread: WindowCloseButton

  1. #1
    Join Date
    May 2009
    Location
    Gorontalo
    Posts
    200
    Thanks
    20
    Thanked 5 Times in 5 Posts
    Qt products
    Platforms
    Unix/X11 Windows

    Question WindowCloseButton

    Why if I use setDetailedText for QMessageBox then WindowCloseButton disabled ? How to enable it ? I tried this, but not work..

    Qt Code:
    1. msg.setDetailedText("Cape Deh...");
    2. msg.setWindowFlags(msg.windowFlags() | Qt::WindowCloseButtonHint);
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: WindowCloseButton

    Please provide a minimal compilable example reproducing the problem.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    May 2009
    Location
    Gorontalo
    Posts
    200
    Thanks
    20
    Thanked 5 Times in 5 Posts
    Qt products
    Platforms
    Unix/X11 Windows

    Question Re: WindowCloseButton

    Qt Code:
    1. QMessageBox msg(this);
    2. msg.setIcon(QMessageBox::Critical);
    3. msg.setWindowTitle("Error");
    4. msg.setText(tr("Sambungan ke database gagal!"));
    5. msg.setDetailedText("Cape Deh...");
    6. msg.setWindowFlags(msg.windowFlags() | Qt::WindowCloseButtonHint);
    7. msg.exec();
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: WindowCloseButton

    I found that there is something like detectedEscapeButton in QMessageBox and setting detailed description causes situation where QMessageBox can't determine detectedEscapeButton so this:
    Qt Code:
    1. void QMessageBox::closeEvent(QCloseEvent *e)
    2. {
    3. if (!d->detectedEscapeButton) {
    4. e->ignore();
    5. return;
    6. }
    7. QDialog::closeEvent(e);
    8. d->clickedButton = d->detectedEscapeButton;
    9. setResult(d->execReturnCode(d->detectedEscapeButton));
    10. }
    To copy to clipboard, switch view to plain text mode 
    means that with detectedEscapeButton set to 0 close event is always ignored.
    In detail: escape button detection is performed on show event. If there is no explicitly set escape button (setEscapeButton) then it is detected which means that QMessageBox search for any button with RejectRole or NoRole or if there is only one button then this one becomes escape button. Adding detailed text adds second button so there is no proper rule to set detectedEscapeButton.
    I found the solution and it is adding yout own button with RejectRole or NoRole but remember that you will get diffrent return code from exec() in this code:
    Qt Code:
    1. msg.setIcon(QMessageBox::Critical);
    2. msg.setWindowTitle("Error");
    3. msg.setText("Sambungan ke database gagal!");
    4. msg.setDetailedText("Cape Deh...");
    5. msg.addButton("OK", QMessageBox::RejectRole);
    6. qDebug("%d", msg.exec()); // here now 0 is returned, with default created OK button it was 1024 (QMessageBox::Ok)
    To copy to clipboard, switch view to plain text mode 
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  5. The following user says thank you to faldzip for this useful post:

    wirasto (8th January 2010)

  6. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: WindowCloseButton

    Why not use setEscapeButton() with the button that already is in the message box?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #6
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: WindowCloseButton

    Quote Originally Posted by wysota View Post
    Why not use setEscapeButton() with the button that already is in the message box?
    I wanted to do so but as I checked QMessageBox::buttons() returnes empty list when used before exec() or show() which is I think the result of this QMessageBox::showEvent():
    Qt Code:
    1. void QMessageBox::showEvent(QShowEvent *e)
    2. {
    3. if (d->autoAddOkButton) {
    4. addButton(Ok);
    5. #if defined(Q_WS_WINCE)
    6. d->hideSpecial();
    7. #endif
    8. }
    9. if (d->detailsButton)
    10. addButton(d->detailsButton, QMessageBox::ActionRole);
    11. d->detectEscapeButton();
    12. d->updateSize();
    13.  
    14. #ifndef QT_NO_ACCESSIBILITY
    15. QAccessible::updateAccessibility(this, 0, QAccessible::Alert);
    16. #endif
    17. #ifdef Q_WS_WIN
    18. HMENU systemMenu = GetSystemMenu((HWND)winId(), FALSE);
    19. if (!d->detectedEscapeButton) {
    20. EnableMenuItem(systemMenu, SC_CLOSE, MF_BYCOMMAND|MF_GRAYED);
    21. }
    22. else {
    23. EnableMenuItem(systemMenu, SC_CLOSE, MF_BYCOMMAND|MF_ENABLED);
    24. }
    25. #endif
    26. QDialog::showEvent(e);
    27. }
    To copy to clipboard, switch view to plain text mode 
    EDIT:
    And here is also code which is graying out close button on windows when there is no detected escaped button which is the case when adding detailed text...
    Last edited by faldzip; 7th January 2010 at 22:52.
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

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.