Last active
July 1, 2019 23:13
-
-
Save stylesuxx/10304993 to your computer and use it in GitHub Desktop.
Expand the widgets inside a scrollArea to the maximum possible size, or the window to the minimum possible size.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "mainwindow.h" | |
#include "ui_mainwindow.h" | |
#include <QVBoxLayout> | |
#include <QScrollArea> | |
#include <QSlider> | |
#include <QWidget> | |
MainWindow::MainWindow(QWidget *parent) : | |
QMainWindow(parent), | |
ui(new Ui::MainWindow) | |
{ | |
ui->setupUi(this); | |
QVBoxLayout *mainLayout = new QVBoxLayout(); | |
// Add sliders to the layout so it overflows the window height for sure | |
for(int i = 0; i < 100; i++) { | |
QSlider *slider = new QSlider(Qt::Horizontal); | |
mainLayout->addWidget(slider); | |
} | |
QWidget *mainWidget = new QWidget(); | |
mainWidget->setLayout(mainLayout); | |
QScrollArea *scrollArea = new QScrollArea(); | |
scrollArea->setWidgetResizable(true); | |
scrollArea->setWidget(mainWidget); | |
setCentralWidget(scrollArea); | |
} | |
MainWindow::~MainWindow() | |
{ | |
delete ui; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment