generated from me/template-mit
43 lines
1.2 KiB
C++
43 lines
1.2 KiB
C++
#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();
|
|
} |