Results 1 to 4 of 4

Thread: Expected behavior of Qt::Tool style?

  1. #1
    Join Date
    Apr 2015
    Posts
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Expected behavior of Qt::Tool style?

    Hello,

    I'm looking at an application bug where on Windows, opening a dialogue causes the program to disappear from the alt-tab menu (though not the taskbar). This seems to be a result of the Qt::Tool flag + WS_EX_TOOLWINDOW style being applied to the dialog widget.
    The widget hierarchy is QMainWindow->QDialog. Is it expected that applying this flag to a child seems to effect the parent, as far as how Windows handles it? I'd assume this would just prevent this dialog window from showing up in these places. Or am I missing something, or is something tragically wrong with the code/app somewhere?

    I tried changing the hierarchy to QMainWindow->QWidget(central widget)->QDialog, with no effect. Making the QDialog a sibling, or removing the Qt::Tool flag does fix the alt-tab issue but is undesirable behavior.

    Seemingly relevant snippets:

    Qt Code:
    1. MainWin::MainWin(QWidget *parent)
    2. : QMainWindow(parent)
    3. {
    4. ui.setupUi(this);
    5. ...
    6. }
    7.  
    8. void MainWin::doClick()
    9. {
    10.  
    11. QScopedPointer<Poppy> theBox(new Poppy(this));
    12. theBox->setModal(true);
    13. theBox->setWindowState(Qt::WindowActive);
    14. theBox->exec();
    15. }
    16.  
    17. Poppy::Poppy(QWidget *parent)
    18. : QDialog(parent)
    19. {
    20. ui.setupUi(this);
    21. this->setWindowFlags(Qt::Tool);
    22. this->setModal(true);
    23. ui.validationWarning->hide();
    24. // connect slots to signals
    25. ...
    26. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Expected behavior of Qt::Tool style?

    What happens if you pass Qt::Tool directly to the QDialog constructor (i.e. QDialog(parent, Qt::Tool)) instead of setting it after construction?

    I do not remember seeing a modal tool window in any GUI. Maybe this unusual pattern was not considered or tested in Qt.

    On a side note, instead of QScopedPointer<Poppy> theBox(new Poppy(this)); you could simply allocate the Poppy on the stack (assuming you do want a modal dialog).

  3. #3
    Join Date
    Apr 2015
    Posts
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Expected behavior of Qt::Tool style?

    Setting it in the constructor does fix it, though it causes the dialog window to be hidden after alt-tabbing. I've seen other threads about that though, with some resolutions. Also, I'll look into your other suggestions after work and see if there's an overall better solution for this widget.

    Out of curiosity without digging into internals, do you know why setting it in the parent constructor would matter? I'd expect a setter and a constructor to have the same end-result.

    Thanks.

  4. #4
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Expected behavior of Qt::Tool style?

    Quote Originally Posted by Valistar View Post
    Out of curiosity without digging into internals, do you know why setting it in the parent constructor would matter? I'd expect a setter and a constructor to have the same end-result.
    I do not know about the internals either, and only relied on what I could find in the documentation, which I find to be somewhat lacking on this particular topic. For instance, the flags passed to the QDialog constructor default to 0, but the documentation states that the non-zero Qt::Dialog flag is on for QDialog by default. This leads me to suspect that the QDialog constructor adds some (unspecified) flags on its own, and that subsequently calling QWidget::setWindowFlags() may clear them. Maybe passing Qt::Tool to the constructor is actually equivalent to calling dialog->setWindowFlags(dialog->windowFlags() | Qt::Tool) afterwards, but this is a mere conjecture.

    Secondly, QWidget::setWindowFlags() warns about setParent() being called, and I admit being suspicious of the effects that might have on a QDialog (whose documentation mentions the Qt::Dialog flag being cleared on that occasion).

Similar Threads

  1. Replies: 3
    Last Post: 1st October 2014, 05:29
  2. Qt Creator A tool for coding style analysis of C/C++ in Qt Creator
    By Slazer in forum Qt Tools
    Replies: 0
    Last Post: 21st September 2012, 20:22
  3. Behavior not expected by QDoubleValidator()
    By vcp in forum Qt Programming
    Replies: 8
    Last Post: 3rd February 2011, 11:15
  4. Style sheets bug? Or normal behavior?
    By Syntho in forum Qt Programming
    Replies: 0
    Last Post: 7th June 2010, 09:16
  5. Grouping of Tool buttons in Tool bar
    By febil in forum Qt Programming
    Replies: 1
    Last Post: 24th March 2009, 11:51

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.