Results 1 to 8 of 8

Thread: QDialog behavior changes when Qt::FramelessWindowHint is applied to it.

  1. #1
    Join Date
    Dec 2006
    Posts
    160
    Thanks
    33
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QDialog behavior changes when Qt::FramelessWindowHint is applied to it.

    Hello,

    i am facing a very weird problem. If i use Qt::FramelessWindowHint when constructing a QDialog, it's behavior is different than when i don't use the frameless flag. So far, i have noticed two major differences but i only have been able to workaround one.

    1) The placement is not the same.
    When calling ->show() on such QDialog-derived classes, the dialog isn't centered to it's parent QDialog. Instead, its top-left corner is being centered. So my workaround for this problem is to call move((this->width()-dlg->width())/2, (height()-dlg->height())/2); No big deal, but very weird.

    2) The accept / reject messages are being "bubbled" to the parent dialog.
    When such frameless dialog is shown, if i press the close button (Directly connected to the close() slot of the dialog), everything is fine. However, if i press ESC, the dialog gets discarded as expected, but the parent dialog too. i am looking for either a solution to this problem, or maybe to another way of making the dialog frameless.

    Note that i'm using Qt OpenSource 4.8.0 on Windows, and it might be interesting to know if the issues are the same on linux / MacOS.

    Thanks,
    Pierre.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QDialog behavior changes when Qt::FramelessWindowHint is applied to it.

    It would help your cause if you posted a minimal, compilable code snippet that demonstrates the problem(s).

  3. #3
    Join Date
    Dec 2006
    Posts
    160
    Thanks
    33
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QDialog behavior changes when Qt::FramelessWindowHint is applied to it.

    Hello,

    Here it is.
    Qt Code:
    1. #ifndef DlgTest_h
    2. #define DlgTest_h
    3.  
    4. #include <QtCore/QDebug>
    5. #include <QtGui/QDialog>
    6. #include <QtGui/QPalette>
    7. #include <QtGui/QTextEdit>
    8. #include <QtGui/QPushButton>
    9. #include <QtGui/QGridLayout>
    10.  
    11. class DlgTest : public QDialog {
    12. Q_OBJECT
    13. public:
    14. /**/ DlgTest (quint32 num, QWidget *p=0, Qt::WFlags f=Qt::FramelessWindowHint|Qt::X11BypassWindowManagerHint)
    15. : QDialog(p, f), _txt(0), _num(num) {
    16. //setWindowFlags ();
    17. if (_num>1)
    18. setModal (true);
    19. // Layout, button, and text box.
    20. QGridLayout *grid = new QGridLayout(this);
    21. QPushButton *btn = new QPushButton(this);
    22. _txt = new QTextEdit(this);
    23. _txt->setText (QString::number(_num));
    24. grid->addWidget (_txt);
    25. grid->addWidget (btn);
    26. setLayout (grid);
    27. // Upon clicking the button, launch another dialog.
    28. connect(btn, SIGNAL(clicked()), this, SLOT(mainButtonClicked()));
    29. };
    30. protected slots:
    31. void mainButtonClicked () {
    32. DlgTest *dlg = new DlgTest(_num+1, this);
    33. connect(dlg, SIGNAL(finished(int)), dlg, SLOT(deleteLater()));
    34. dlg->show ();
    35. qDebug() << dlg->geometry();
    36. };
    37. private:
    38. QTextEdit *_txt;
    39. quint32 _num;
    40. };
    41.  
    42. #endif
    To copy to clipboard, switch view to plain text mode 
    You will start the first instance of this dialog with this in your main():
    Qt Code:
    1. DlgTest dlg (1, (QWidget*)QApplication::desktop());
    2. dlg.show();
    To copy to clipboard, switch view to plain text mode 

    Now, you will try the code with the flags that are in the constructor. Each new dialog will be offsetted.
    After testing with these flags, you will replace "Qt::FramelessWindowHint|Qt::X11BypassWindowManage rHint" by 0, and try again.
    The behavior i get with this minimal example isn't even the same as the one i have in my app... The offset being negative, in my app it's positive.
    And the "ESC" problem isn't even here, so i guess it's related to something else i do in my app... i'll try to dig further.

    Sorry for the indentation... Visual studio doesn't seem to understand what soft tabs are on this computer.

    [edit]
    i found what to do to reproduce the ESC bug. Remove the flags from the constructor (Replace them by 0 by default). Then, put this in the constructor:
    Qt Code:
    1. setWindowFlags(Qt::Dialog|Qt::FramelessWindowHint|Qt::X11BypassWindowManagerHint);
    To copy to clipboard, switch view to plain text mode 
    i have tried:
    Qt Code:
    1. setWindowFlags(windowFlags()|Qt::FramelessWindowHint|Qt::X11BypassWindowManagerHint);
    To copy to clipboard, switch view to plain text mode 
    But the result is even different and unusable. So maybe i misunderstood the use of those flags?
    [/edit]

    Pierre.
    Last edited by hickscorp; 5th April 2012 at 11:29.

  4. #4
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QDialog behavior changes when Qt::FramelessWindowHint is applied to it.

    Your dialog changes position because of sanity check in QDialog::adjustPosition().
    Frameless windows will be offseted from their parent by (minus) 10x40px.

    I would expect the linux to behave the same (I haven't checked it though).

    As to the ESC issue - I couldn't reproduce it. Works fine for me no mater what I do (qt 4.6.3, w7).

    If you're looking for a different way to make dialog 'frameless' then add this to your dialog (and get rid of all other flags):
    Qt Code:
    1. void resizeEvent( QResizeEvent* )
    2. {
    3. this->setMask( QRegion( this->rect() ) );
    4. }
    To copy to clipboard, switch view to plain text mode 

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

    hickscorp (9th April 2012)

  6. #5
    Join Date
    Dec 2006
    Posts
    160
    Thanks
    33
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QDialog behavior changes when Qt::FramelessWindowHint is applied to it.

    Hello Spitfire, and thanks a lot for your help.

    Your technique is very interesting, and i will try it.
    As for the modals dialogs disappearing all at the same time when pressing ESC, i have found a workaround (Which is kind of ugly and forces me to keep track of windows orders, hide them, show them, etc so i can make the dialogs non-modal without risking to allow the user to change values in the parent windows).

    If you are interested in reproducing the ESC bug, make my example dialog class modal (setModal(true)).

    Thanks again!
    Pierre.

  7. #6
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QDialog behavior changes when Qt::FramelessWindowHint is applied to it.

    I've tried both modal and non-modal dialogs and in both cases ESC acts as expected (unless you press and hold it).

    I personally believe you're doing something wrong as this should not happen.
    Are you handling events yourself somewhere?

    I don't have Qt 4.8 to try at the moment but I don't think it's a Qt issue.

  8. #7
    Join Date
    Dec 2006
    Posts
    160
    Thanks
    33
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QDialog behavior changes when Qt::FramelessWindowHint is applied to it.

    Hello again Spitfire!

    i'm not handling events (The example i have posted reproduces the problem on my environment, Windows XP and Qt 4.8.0 compiled as dynamic).
    i will try to make a small video showing the issue if i get a bit time to do so.

    Thanks for your help,
    Pierre.

  9. #8
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QDialog behavior changes when Qt::FramelessWindowHint is applied to it.

    I've tested your class on w7 qt 4.8.1 (vm) and everything works as expected.

Similar Threads

  1. Curve Fitting Not Always Applied
    By Mannion in forum Qwt
    Replies: 3
    Last Post: 16th March 2011, 08:11
  2. KDE 3 style applied to Qt 4 programs
    By alecs1 in forum KDE Forum
    Replies: 4
    Last Post: 4th December 2008, 21:24
  3. setWindowFlags(Qt::FramelessWindowHint)
    By smarinr in forum Qt Programming
    Replies: 5
    Last Post: 30th April 2008, 20:12
  4. Confused QWidget and QDialog behavior
    By munna in forum Qt Programming
    Replies: 1
    Last Post: 9th December 2006, 12:14
  5. Qt::FramelessWindowHint
    By L.Marvell in forum Qt Programming
    Replies: 16
    Last Post: 6th May 2006, 16:27

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.