Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to get the height and the width of the MainWindow::MainWindow(QWidget *parent) ?
Forum Update on Monday, May 27th 2025

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

Scheduled Pinned Locked Moved Unsolved General and Desktop
mainwindowparentwidthheight
3 Posts 3 Posters 20.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Touchoco
    wrote on 18 Nov 2015, 18:11 last edited by
    #1

    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.

    1 Reply Last reply
    0
    • R Offline
      R Offline
      Rondog
      wrote on 18 Nov 2015, 18:52 last edited by
      #2

      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.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mrjj
        Lifetime Qt Champion
        wrote on 18 Nov 2015, 20:25 last edited by
        #3

        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.

        1 Reply Last reply
        0

        1/3

        18 Nov 2015, 18:11

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved