QT Example Programs
QT Example Programs
#include <QtGui> int main(int argc, char *argv[]) { QApplication app(argc, argv); QWidget window; window.resize(320, 240); window.show(); window.setWindowTitle( QApplication::translate("toplevel", "Top-level widget")); return app.exec(); }
Child Widgets
#include <QtGui> int main(int argc, char *argv[]) { QApplication app(argc, argv); QWidget window; window.resize(320, 240); window.setWindowTitle(QApplication::translate("childwidget", "Child widget")); window.show(); QPushButton *button = new QPushButton( QApplication::translate("childwidget", "Press me"), &window); button->move(100, 100); button->show(); return app.exec(); }
Using Layouts
#include <QtGui> int main(int argc, char *argv[]) { QApplication app(argc, argv); QWidget window; QLabel *label = new QLabel(QApplication::translate("windowlayout", "Name:")); QLineEdit *lineEdit = new QLineEdit(); QHBoxLayout *layout = new QHBoxLayout(); layout->addWidget(label); layout->addWidget(lineEdit); window.setLayout(layout); window.setWindowTitle( QApplication::translate("windowlayout", "Window layout")); window.show(); return app.exec(); }
Nested Layouts
#include <QtGui> int main(int argc, char *argv[]) { QApplication app(argc, argv); QWidget window; QLabel *queryLabel = new QLabel( QApplication::translate("nestedlayouts", "Query:")); QLineEdit *queryEdit = new QLineEdit(); QTableView *resultView = new QTableView(); QHBoxLayout *queryLayout = new QHBoxLayout(); queryLayout->addWidget(queryLabel); queryLayout->addWidget(queryEdit); QVBoxLayout *mainLayout = new QVBoxLayout(); mainLayout->addLayout(queryLayout); mainLayout->addWidget(resultView); window.setLayout(mainLayout); // Set up the model and configure the view... window.setWindowTitle( QApplication::translate("nestedlayouts", "Nested layouts")); window.show(); return app.exec(); }