Results 1 to 3 of 3

Thread: QMainWindow and its QDockWidget

  1. #1
    Join Date
    Jan 2006
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Question QMainWindow and its QDockWidget

    Hi everybody,
    I have a simple QMainWindow with a QDockWidget (a tool box) and a central widget (see the joined file called MainWindow1.jpg I don't know how to insert them directly in the text).
    When I click on one button of the tool box, I need to change the central widget of the main window :
    Qt Code:
    1. QPushButton *quit = new QPushButton(tr("&Quit"));
    2. quit->setFont(QFont("Times", 18, QFont::Bold));
    3. quit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
    4.  
    5. delete centralWidget();
    6. setCentralWidget(quit);
    7.  
    8. updateGeometry();
    9. update();
    To copy to clipboard, switch view to plain text mode 

    But the problem is that the dock widget (the tool box) now takes a half of the main window horizontaly !!!! (see MainWindow2.jpg)

    To avoid the resizing of the dock widget I wrote the following code:

    Qt Code:
    1. setMinimumWidth(m_toolBox->width());
    2. setMaximumWidth(m_toolBox->width());
    To copy to clipboard, switch view to plain text mode 

    The result was not what I expected : the dock widget is correctly resized but there is a kind of frame taking a half of the main window !!!! (see MainWindow3.jpg)

    Somebody have an idea?
    Attached Images Attached Images

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QMainWindow and its QDockWidget

    The docs say:
    void QMainWindow::setCentralWidget ( QWidget * widget )
    Sets the given widget to be the main window's central widget.
    Warning: This function should be called at most once for each main window instance
    Maybe you should use QStackedWidget as a central widget?

  3. #3
    Join Date
    Jan 2006
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QMainWindow and its QDockWidget

    Thanks for your advice. It's true that the behaviour was not very nice.

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.