#include#include #include int main(int argc, char *argv[]) { QApplication app(argc, argv); QMainWindow window; window.setWindowTitle("QToolBar addWidget Example"); QToolBar *toolBar = new QToolBar(&window); window.addToolBar(toolBar); QPushButton *button = new QPushButton("Click Me", toolBar); toolBar->addWidget(button); window.show(); return app.exec(); }
#includeThis example creates a QMainWindow with a QToolBar and adds a QLabel to the QToolBar using the addWidget function. The QLabel is instantiated with the QToolBar as its parent and displays the text "Hello, World!". Package library: Qt#include #include int main(int argc, char *argv[]) { QApplication app(argc, argv); QMainWindow window; window.setWindowTitle("QToolBar addWidget Example"); QToolBar *toolBar = new QToolBar(&window); window.addToolBar(toolBar); QLabel *label = new QLabel("Hello, World!", toolBar); toolBar->addWidget(label); window.show(); return app.exec(); }