Results 1 to 4 of 4

Thread: QDialog problem when setting mainwindow as parent

  1. #1
    Join Date
    Jul 2011
    Posts
    42
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question QDialog problem when setting mainwindow as parent

    We have a mainwindow class that inherits from QMainWindow. We use this flags:
    Qt Code:
    1. setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
    To copy to clipboard, switch view to plain text mode 

    Before starting the aplication we display a QDialog with some text. If we create this QDialog with the mainwindow as the parent, some weird things happen when animating de mainwindow.

    At some point in the program we need to expand down the mainwindow to show a progressbar. When doing this, misteriously the mainwindow gets expanded down, but it also losses width. Each time we expand it down, the width decreses. This behaviour ONLY happens when creating the QDialog with mainwindow as parent, if using parent NULL, evertyhing works fine.

    Qt Code:
    1. QDialog* eulaWin = new QDialog(this, Qt::Dialog | Qt::Window | Qt::WindowStaysOnTopHint );
    To copy to clipboard, switch view to plain text mode 

    and this is the expand method in the custom utility class for animations:
    (expand down => FX_DOWN)
    Qt Code:
    1. void FXManager::expand(QWidget *widget, int direction, int speed, int ratio, QEasingCurve easingCurve)
    2. {
    3. QPropertyAnimation* animationFrame = new QPropertyAnimation(widget, "geometry", widget);
    4.  
    5. animationFrame->setDuration(speed);
    6. animationFrame->setEasingCurve(easingCurve);
    7.  
    8. animationFrame->setStartValue(QRect(widget->geometry().x(),widget->geometry().y(), widget->geometry().width(), widget->geometry().height()));
    9.  
    10. switch(direction)
    11. {
    12. case (int)FX_LEFT: animationFrame->setEndValue(QRect(widget->geometry().x() - ratio,widget->geometry().y()+0, widget->geometry().width() + ratio, widget->geometry().height()));
    13. break;
    14. case (int)FX_RIGHT: animationFrame->setEndValue(QRect(widget->geometry().x()+0,widget->geometry().y()+0, widget->geometry().width() + ratio, widget->geometry().height()));
    15. break;
    16. case (int)FX_UP: animationFrame->setEndValue(QRect(widget->geometry().x()+0,widget->geometry().y() - ratio, widget->geometry().width(), widget->geometry().height() + ratio));
    17. break;
    18. case (int)FX_DOWN: animationFrame->setEndValue(QRect(widget->geometry().x()+0,widget->geometry().y()+0, widget->geometry().width(), widget->geometry().height() + ratio));
    19. break;
    20. }
    21.  
    22. animationFrame->start(QPropertyAnimation::DeleteWhenStopped);
    23.  
    24. widget->repaint();
    25. QApplication::processEvents();
    26. }
    To copy to clipboard, switch view to plain text mode 

    The basic idea if the expand method is to expand down (or in any direction choosed) as many pixels as specified in the ratio param. Thus we maintain the original position and width.

    Any ideas why this could be happening?
    Last edited by superpacko; 20th July 2011 at 16:51. Reason: spelling corrections

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QDialog problem when setting mainwindow as parent

    Before starting the aplication we display a QDialog with some text.
    is your mainwindow visible at that time?
    If not, that is the reason for your problems.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Jul 2011
    Posts
    42
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QDialog problem when setting mainwindow as parent

    well, at the constructor of the mainwindow we are showing that QDialog, so if the user acepts then the constructor finishes and displays the window, otherwhise it will quit the aplication.
    So i guess the mainwindow is not visible nor active at the time we create the dialog.

    But I still dot get it, once the user accepted the dialog, the mainwindow is visible and the dialog hidden. How could the creation of the QDialog affect the mainwindow? do you have any idea why is affecting the expanding effect?

    thanks a lot!

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QDialog problem when setting mainwindow as parent

    well, at the constructor of the mainwindow we are showing that QDialog,
    At this point the mainwindow is not yet visible, nor is it fully constructed, so geometry information is not valid, which explains any trouble related to geometry such as you do:
    animating and expanding.
    How could the creation of the QDialog affect the mainwindow? do you have any idea why is affecting the expanding effect?
    Well, if the dialog is modal, it stops the even loop for the mainwindow.
    Other than that, you are giving the dialog a non visible, not fully created parent, so I would expect even the dialog not to show, unless its modal, and I am not sure what the modal dialog does with such "half backed" parent.
    But having a visible widget with an invisible parent, is just asking for trouble.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

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

    superpacko (21st July 2011)

Similar Threads

  1. Replies: 2
    Last Post: 24th January 2010, 13:46
  2. SETTING THE TEXT COLOR FOR QMessageBox
    By vinkakarun in forum Newbie
    Replies: 2
    Last Post: 5th November 2009, 17:32
  3. setting background color of QMessageBox
    By wagmare in forum Qt Programming
    Replies: 7
    Last Post: 23rd May 2009, 14:26
  4. MainWindow disappearing when loading a QMessageBox
    By fabietto in forum Qt Programming
    Replies: 14
    Last Post: 26th June 2008, 00:41
  5. Setting QMessageBox geometry
    By Krish_ng in forum Qt Programming
    Replies: 3
    Last Post: 25th July 2007, 15:47

Tags for this Thread

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.