PDA

View Full Version : show() in central main window



ufo-vl
27th July 2007, 06:23
Hello,



QDialog dlg( this );
dlg.show();


as result dialog window showed in random place,
can I show the dialog in main window central position?

now, for this task I use the following code:


QDialog dlg( this );
moveToCenter( &dlg );

void SMainWindow::moveToCenter( QWidget* child )
{
if ( child->parentWidget( ) )
{
QSize szParent = child->parentWidget( )->size( );
QPoint ptChild = QPoint( ( szParent.width( ) - child->size( ).width( ) ) / 2,
( szParent.height( ) - child->size( ).height( ) ) / 2 );
child->move( ptChild );
}
}


There are other ways?

marcel
27th July 2007, 07:18
Yeah, if it works then use it.
There is no straightforward way to do that.

Regards

jpn
27th July 2007, 15:57
I thought dialogs with a parent got automatically centered.


A dialog is always a top-level widget, but if it has a parent, its default location is centered on top of the parent's top-level widget (if it is not top-level itself). It will also share the parent's taskbar entry.

ufo-vl
28th July 2007, 02:33
thanks for your messages