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. Getting widget size and position
Forum Updated to NodeBB v4.3 + New Features

Getting widget size and position

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 810 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.
  • B Offline
    B Offline
    BKBK
    wrote on last edited by
    #1

    Qt and Linux novice, Qt version 3. I cannot copy paste from my work computer to here so please try to accommodate typos.
    The question:
    What code is used to get the size of a widget and its location on the screen?
    Details:
    Getting the size and position of the first widget is proving more difficult than expected so I created a new project with just one widget and some fields that show the noted values. The widget constructor sets the min width set to 666 and min height set to 222. It opens in the top left corner of the monitor leading to the presumption that the location is X and Y = zero. Here are the snippets:

    QString text;
    text = QString( %1".arg( x( ) );
    m_le_x_pos->setText( text );  // a line edit box to display the values
    text = QString( %1".arg( y( ) );
    m_le_y_pos->setText( text );
    

    The values returned are 800 and 360. I cannot make any sense of those two numbers. The left and top are zero and the right and bottom should be 666 and 222.

    QRect fg = frameGeometry()
    text = QString( %1".arg( fg.top( ) );
    m_le_top->setText( text );    // produces the value 360
    text = QString( %1".arg( fg.bottom( ) );
    m_le_bottom->setText( text );    // produces the value 839
    

    I am unable to determine the meanings of those values.

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Is you widget in a layout or something like this? When do you retrieve the values? You must not read them when the widget is not yet shown (which is the case e.g. in the ctor)

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      2
      • B Offline
        B Offline
        BKBK
        wrote on last edited by BKBK
        #3

        The values were being fetched from within the constructor. Moving the query code out, into a function, and adding a pushbutton to call the function made the difference. The widget can be moved around and the button clicked to see how the values change. Now I can make sense of the numbers.
        Thank you for your time.

        1 Reply Last reply
        0

        • Login

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