QScrollArea odd sizes
-
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; }
-
@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.