Results 1 to 4 of 4

Thread: show() in central main window

  1. #1
    Join Date
    Jul 2007
    Posts
    27
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default show() in central main window

    Hello,

    Qt Code:
    1. QDialog dlg( this );
    2. dlg.show();
    To copy to clipboard, switch view to plain text mode 

    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:
    Qt Code:
    1. QDialog dlg( this );
    2. moveToCenter( &dlg );
    3.  
    4. void SMainWindow::moveToCenter( QWidget* child )
    5. {
    6. if ( child->parentWidget( ) )
    7. {
    8. QSize szParent = child->parentWidget( )->size( );
    9. QPoint ptChild = QPoint( ( szParent.width( ) - child->size( ).width( ) ) / 2,
    10. ( szParent.height( ) - child->size( ).height( ) ) / 2 );
    11. child->move( ptChild );
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 

    There are other ways?
    Excuse me for English, I from Russia

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: show() in central main window

    Yeah, if it works then use it.
    There is no straightforward way to do that.

    Regards

  3. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: show() in central main window

    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.
    J-P Nurmi

  4. #4
    Join Date
    Jul 2007
    Posts
    27
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default Re: show() in central main window

    thanks for your messages
    Excuse me for English, I from Russia

Similar Threads

  1. New to QT, problem displaying main window...
    By McCall in forum Qt Programming
    Replies: 4
    Last Post: 15th June 2007, 14:27
  2. move parent window to the front.
    By hvengel in forum Qt Programming
    Replies: 4
    Last Post: 2nd February 2007, 08:41
  3. Replies: 5
    Last Post: 4th August 2006, 23:44
  4. cannot make a main window modal
    By Dark_Tower in forum Qt Programming
    Replies: 12
    Last Post: 23rd March 2006, 10:21
  5. Main window
    By Michiel in forum Qt Tools
    Replies: 1
    Last Post: 20th March 2006, 23:54

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.