How to get the height and the width of the MainWindow::MainWindow(QWidget *parent) ?



  • Hi everybody,
    I'm a begginer in Qt
    I need to get the size of my window to adjust my tab but I don't know how to do.
    Could you help me please ?
    Thank you.



  • You can call the 'size' function from any widget. If you call this from the main window it will return the size of the main window.

    QSIze size = this->size();
    

    In some cases the size may not be correct (in the constructor before the widget is completely created or displayed) until after the widget is first shown. Deferring this to the first call of resizeEvent() is a good idea.


  • Qt Champions 2016

    Besides what @Rondog mentions, you could also read about layouts
    http://doc.qt.io/qt-5.5/designer-layouts.html

    If you assign a layout to the window, and put the tab in it, Qt can then
    automatically adjust the size if user resize the window.
    It takes a little bit to learn layouts but the reward is great.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.