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. QScrollArea odd sizes
QtWS25 Last Chance

QScrollArea odd sizes

Scheduled Pinned Locked Moved General and Desktop
qscrollareaqopenglwi
4 Posts 2 Posters 1.5k 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.
  • F Offline
    F Offline
    Fundies
    wrote on last edited by Fundies
    #1

    My qscrollarea is changing size sometime after creation and I don't understand why.
    Why is scrollArea->width() = 500 during the first qdebug but its 400 when I press a key later?

    #include "ui_mainwindow.h"
    #include <QHBoxLayout>
    #include <QOpenGLWidget>
    #include <QDebug>
    
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
    
        QWidget *mCentralWidget = new QWidget(this);
        setCentralWidget(mCentralWidget);
    
        QHBoxLayout *mainLayout = new QHBoxLayout;
        mainLayout->setMargin(0);
        mCentralWidget->setLayout(mainLayout);
    
    
        QOpenGLWidget* mCanvas = new QOpenGLWidget(this);
        mCanvas->resize(500, 175);
        mCanvas->setMinimumSize(500, 175);
    
        scrollArea = new QScrollArea;
        scrollArea->setWidget(mCanvas);
        scrollArea->setWidgetResizable(true);
        mainLayout->addWidget(scrollArea);
        scrollArea->resize(500,175);
    
        qDebug() << mCanvas->width();
        qDebug() << scrollArea->width();
    
    }
    
    void MainWindow::keyPressEvent(QKeyEvent * event)
    {
        qDebug() << scrollArea->width();
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    
    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Fundies said:

      For Me it just looks like all get adjusted to the size of the MainWindow.
      so In the constructor the sizing has not yet fully happened and later
      in keypress it has.

      if I insert
      setGeometry(50,50,500,500);
      just after
      ui->setupUi(this);

      I get same value before and after keypress.

      1 Reply Last reply
      0
      • F Offline
        F Offline
        Fundies
        wrote on last edited by
        #3

        I want the mainwindow to adjust to the size of the contents not the otherway around...

        mrjjM 1 Reply Last reply
        0
        • F Fundies

          I want the mainwindow to adjust to the size of the contents not the otherway around...

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Fundies
          The Mainwindow has the size you make it in forms designer or the size you give it in code.
          It will not adjust size to the widgets it owns so you must do it. They adjust to it.

          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