forked from SEAME-pt/SEAME-Course-24-25
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
code examples: improve qt hello world
- Loading branch information
1 parent
4706ce1
commit 519f30b
Showing
4 changed files
with
56 additions
and
62 deletions.
There are no files selected for viewing
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,59 @@ | ||
#include <qapplication.h> | ||
|
||
#include <QApplication> | ||
#include <memory> | ||
#include <QFont> | ||
#include <QGridLayout> | ||
#include <QLCDNumber> | ||
#include <QPushButton> | ||
#include <QSlider> | ||
#include <QVBoxLayout> | ||
#include <QWidget> | ||
|
||
class LCDRange : public QWidget { | ||
public: | ||
explicit LCDRange(QWidget *parent = nullptr); | ||
}; | ||
|
||
#include "hello.hpp" | ||
LCDRange::LCDRange(QWidget *parent) : QWidget(parent) { | ||
QLCDNumber *lcd = new QLCDNumber(2); | ||
lcd->setSegmentStyle(QLCDNumber::Filled); | ||
|
||
auto main(int argc, char **argv) -> int { | ||
QApplication const app(argc, argv); | ||
QSlider *slider = new QSlider(Qt::Horizontal); | ||
slider->setRange(0, 99); | ||
slider->setValue(0); | ||
connect(slider, SIGNAL(valueChanged(int)), lcd, SLOT(display(int))); | ||
|
||
QVBoxLayout *layout = new QVBoxLayout; | ||
layout->addWidget(lcd); | ||
layout->addWidget(slider); | ||
setLayout(layout); | ||
} | ||
|
||
const int WindowWidth = 600; | ||
const int WindowHeight = 600; | ||
class MyWidget : public QWidget { | ||
public: | ||
explicit MyWidget(QWidget *parent = nullptr); | ||
}; | ||
|
||
auto mainWidget = std::make_unique<MyWidget>(); | ||
mainWidget->resize(WindowWidth, WindowHeight); | ||
mainWidget->show(); | ||
MyWidget::MyWidget(QWidget *parent) : QWidget(parent) { | ||
QPushButton *quit = new QPushButton(tr("Quit")); | ||
quit->setFont(QFont("Times", 18, QFont::Bold)); | ||
connect(quit, SIGNAL(clicked()), qApp, SLOT(quit())); | ||
|
||
QGridLayout *grid = new QGridLayout; | ||
for (int row = 0; row < 3; ++row) { | ||
for (int column = 0; column < 3; ++column) { | ||
auto *lcdRange = new LCDRange; | ||
grid->addWidget(lcdRange, row, column); | ||
} | ||
} | ||
|
||
QVBoxLayout *layout = new QVBoxLayout; | ||
layout->addWidget(quit); | ||
layout->addLayout(grid); | ||
setLayout(layout); | ||
} | ||
|
||
return QApplication::exec(); | ||
auto main(int argc, char *argv[]) -> int { | ||
QApplication app(argc, argv); | ||
MyWidget widget; | ||
widget.show(); | ||
return app.exec(); | ||
} |