0% found this document useful (0 votes)
64 views2 pages

QT Example Programs

The document contains 4 code examples that demonstrate creating windows and using layouts in Qt GUI applications. The first example creates a basic window. The second adds a button widget to the window. The third uses layouts to position a label and text box. The fourth nests layouts to position a query label and text box above a results table.

Uploaded by

praveenlark
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views2 pages

QT Example Programs

The document contains 4 code examples that demonstrate creating windows and using layouts in Qt GUI applications. The first example creates a basic window. The second adds a button widget to the window. The third uses layouts to position a label and text box. The fourth nests layouts to position a query label and text box above a results table.

Uploaded by

praveenlark
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

Creating a Window

#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(); }

You might also like