PDA

View Full Version : Align QDialog



sousadaniel7
2nd May 2012, 20:38
Hello
I need to change the size of a QDialog during its execution and that the utilizao this.setGeometry (0,0,500,700). The problem is that QDialog appears in the top left corner that is in position (0,0). Is there any function that allows for a QDialog in the center of the screen?



Daniel Sousa

Lykurg
2nd May 2012, 21:21
use
dialog->setGeometry(QStyle::alignedRect(Qt::LeftToRight, Qt::AlignCenter, dialog->size(), qApp->desktop()->availableGeometry()));

sousadaniel7
2nd May 2012, 21:52
use
dialog->setGeometry(QStyle::alignedRect(Qt::LeftToRight, Qt::AlignCenter, dialog->size(), qApp->desktop()->availableGeometry()));

It works perfectly. Thank you.

sousadaniel7
3rd May 2012, 21:21
use
dialog->setGeometry(QStyle::alignedRect(Qt::LeftToRight, Qt::AlignCenter, dialog->size(), qApp->desktop()->availableGeometry()));

Is there any way to set the size of QDialog that function?

Lykurg
4th May 2012, 14:06
substitute dialog->size() with any size (QSize) you want.

sousadaniel7
4th May 2012, 15:44
substitute dialog->size() with any size (QSize) you want.

I did the following:

this->setGeometry(QStyle::alignedRect(Qt::LeftToRight, Qt::AlignCenter, 88, qApp->desktop()->availableGeometry()));

But he gave me the following error:

/Users/danielsousa/Qt/Interface-build-desktop-Desktop_Qt_4_8_1_for_GCC__Qt_SDK__Release/../Interface2/criareditaralerta.cpp:15: error: no matching function for call to 'QStyle::alignedRect(Qt::LayoutDirection, Qt::AlignmentFlag, int, const QRect)'

totem
4th May 2012, 16:10
yea well, 88 is an int, not a QSize. And there is no QSize implicit constructor with an single int as argument
The error message is quite explicit btw

sousadaniel7
4th May 2012, 17:37
yea well, 88 is an int, not a QSize. And there is no QSize implicit constructor with an single int as argument
The error message is quite explicit btw

Yeah, but then how can I fix this?

totem
4th May 2012, 19:38
consider this a minute.
In the previous version, you wrote

dialog->setGeometry(QStyle::alignedRect(Qt::LeftToRight, Qt::AlignCenter, dialog->size(), qApp->desktop()->availableGeometry()));
then, you want to change QDialog's size. So, as lykurg said, you replace dialog->size() by the QSize you want.

now, what is the QSize you choose ?
88
88 is not a QSize

Q.E.D.

Lykurg
4th May 2012, 19:39
Read the documentation about QSize (just click the link!). See which constructors are provided.