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. When size of viewport is defined?
Qt 6.11 is out! See what's new in the release blog

When size of viewport is defined?

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.1k Views 1 Watching
  • 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.
  • A Offline
    A Offline
    alan73
    wrote on last edited by
    #1

    Hello!

    I'm writing app with QScrollArea and going to set scroll bars values. Here's a piece of code:

    @
    MyScrollArea::MyScrollArea() {
    ...
    // create scrollarea's widget
    CentralWidget = new QWidget(viewport());
    setWidget(CentralWidget);

    // set scrollarea's widget geometry
    CentralWidget->setGeometry(0, 0, someWidth, someHeight);
    CentralWidget->show();
    CentralWidget->repaint();
    
    // get viewport size
    int viewWidth  = viewport()->width();
    int viewHeight = viewport()->height();
    //--------------------------------------------
    

    }@

    And got incorrect size of viewport: viewWidth = 28, viewHeight = 98. I consider that it's not defined yet, is it right?. When will I be able to get correct size?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      adolby
      wrote on last edited by
      #2

      Here's an explanation of what may be happening to you:

      http://qt-project.org/forums/viewthread/5084

      You can likely use Volker's solution to overcome this.

      Also, you can try calling show() first, then setGeometry() in your example, since you'll know someWidth and someHeight.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        alan73
        wrote on last edited by
        #3

        Thanks for reply! Maybe a bit later, but I'll try :)

        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