In Qt and Unix terminology, a widget is a visual
element in a user interface. The term stems from "window gadget"Widgets can contain other widgets; for example, an application window is usually a widget that contains a QMenuBar, a few QToolBars, a QStatusBar, and some other widgets.
1 #include <QApplication>
2 #include <QLabel>
3 int main(int argc, char *argv[])
4 {
5 QApplication app(argc, argv);
6 QLabel *label = new QLabel("Hello Qt!");
7 label->show();//Line 7 makes the label visible. Widgets are always created hidden
8 return app.exec();//Line 8 the program enters the event loop.
9 }
compile:
qmake -project //create a platform-independent project file (hello.pro),
qmake hello.pro //to create a platform-specific makefile from the project file.
ps: QLabel *label = new QLabel("<h2><i>Hello</i> "
"<font color=red>Qt!</font></h2>");
it's easy to brighten up a Qt application's user interface using some simple HTML-style formatting.