PDA

View Full Version : QDialog problem when setting mainwindow as parent



superpacko
20th July 2011, 16:44
We have a mainwindow class that inherits from QMainWindow. We use this flags:


setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);


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.



QDialog* eulaWin = new QDialog(this, Qt::Dialog | Qt::Window | Qt::WindowStaysOnTopHint );


and this is the expand method in the custom utility class for animations:
(expand down => FX_DOWN)


void FXManager::expand(QWidget *widget, int direction, int speed, int ratio, QEasingCurve easingCurve)
{
QPropertyAnimation* animationFrame = new QPropertyAnimation(widget, "geometry", widget);

animationFrame->setDuration(speed);
animationFrame->setEasingCurve(easingCurve);

animationFrame->setStartValue(QRect(widget->geometry().x(),widget->geometry().y(), widget->geometry().width(), widget->geometry().height()));

switch(direction)
{
case (int)FX_LEFT: animationFrame->setEndValue(QRect(widget->geometry().x() - ratio,widget->geometry().y()+0, widget->geometry().width() + ratio, widget->geometry().height()));
break;
case (int)FX_RIGHT: animationFrame->setEndValue(QRect(widget->geometry().x()+0,widget->geometry().y()+0, widget->geometry().width() + ratio, widget->geometry().height()));
break;
case (int)FX_UP: animationFrame->setEndValue(QRect(widget->geometry().x()+0,widget->geometry().y() - ratio, widget->geometry().width(), widget->geometry().height() + ratio));
break;
case (int)FX_DOWN: animationFrame->setEndValue(QRect(widget->geometry().x()+0,widget->geometry().y()+0, widget->geometry().width(), widget->geometry().height() + ratio));
break;
}

animationFrame->start(QPropertyAnimation::DeleteWhenStopped);

widget->repaint();
QApplication::processEvents();
}


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?

high_flyer
20th July 2011, 17:53
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.

superpacko
20th July 2011, 18:36
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!

high_flyer
21st July 2011, 10:35
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.