Last active
August 29, 2015 14:25
-
-
Save devinacker/1777c8f712953d8870e5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| /* compile as C++11 */ | |
| #include <QApplication> | |
| #include <QPushButton> | |
| #include <QSlider> | |
| #include <QLabel> | |
| #include <QLayout> | |
| int main(int argc, char *argv[]) | |
| { | |
| QApplication a(argc, argv); | |
| QWidget w; | |
| w.setWindowTitle("QWidget Size Test"); | |
| QVBoxLayout *layout = new QVBoxLayout; | |
| w.setLayout(layout); | |
| int defaultSize = 20; | |
| QPushButton *button = new QPushButton; | |
| layout->addWidget(button); | |
| layout->addStretch(); | |
| button->setMinimumSize(defaultSize, defaultSize); | |
| button->setMaximumSize(defaultSize, defaultSize); | |
| QGridLayout *grid = new QGridLayout; | |
| layout->addLayout(grid); | |
| grid->addWidget(new QLabel("Minimum Height"), 0, 0); | |
| grid->addWidget(new QLabel("Minimum Width"), 1, 0); | |
| QSlider *heightSlider = new QSlider(Qt::Horizontal); | |
| grid->addWidget(heightSlider, 0, 1); | |
| heightSlider->setRange(defaultSize, 500); | |
| QObject::connect(heightSlider, &QSlider::valueChanged, [=](int height) { | |
| button->setMinimumHeight(height); | |
| }); | |
| QSlider *widthSlider = new QSlider(Qt::Horizontal); | |
| grid->addWidget(widthSlider, 1, 1); | |
| widthSlider->setRange(defaultSize, 500); | |
| QObject::connect(widthSlider, &QSlider::valueChanged, [=](int width) { | |
| button->setMinimumWidth(width); | |
| }); | |
| w.show(); | |
| return a.exec(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment