generated from me/template-mit
Add example project.
This commit is contained in:
1 parent
0bea8e4901
commit
bb38215c04
3 files changed
+78
-2
No files matched your search
@@ -0,0 +1,43 @@
|
||||
#include <QApplication>
|
||||
#include <QMainWindow>
|
||||
#include <QPushButton>
|
||||
#include <QLabel>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
QApplication app(argc, argv);
|
||||
|
||||
QMainWindow mainWindow;
|
||||
mainWindow.setWindowTitle("Hello World Qt");
|
||||
mainWindow.resize(400, 300);
|
||||
|
||||
// Create central widget and layout
|
||||
QWidget *centralWidget = new QWidget(&mainWindow);
|
||||
QVBoxLayout *layout = new QVBoxLayout(centralWidget);
|
||||
|
||||
// Create hello world label
|
||||
QLabel *helloLabel = new QLabel("Hello World!", centralWidget);
|
||||
helloLabel->setAlignment(Qt::AlignCenter);
|
||||
helloLabel->setStyleSheet("font-size: 24px; font-weight: bold;");
|
||||
|
||||
// Create close button
|
||||
QPushButton *closeButton = new QPushButton("Close", centralWidget);
|
||||
closeButton->setStyleSheet("font-size: 16px; padding: 10px;");
|
||||
|
||||
// Connect button to close action
|
||||
QObject::connect(closeButton, &QPushButton::clicked, &mainWindow, &QMainWindow::close);
|
||||
|
||||
// Add widgets to layout
|
||||
layout->addStretch();
|
||||
layout->addWidget(helloLabel);
|
||||
layout->addWidget(closeButton);
|
||||
layout->addStretch();
|
||||
|
||||
// Set central widget
|
||||
mainWindow.setCentralWidget(centralWidget);
|
||||
|
||||
// Show the window
|
||||
mainWindow.show();
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
Reference in new issue
Block a user