When size of viewport is defined?

  • 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());

    // set scrollarea's widget geometry
    CentralWidget->setGeometry(0, 0, someWidth, someHeight);
    // 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?

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


    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.

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

Log in to reply

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