In this tutorial we will learn how to Add tab to QTabWidget.
Step 1 – File->Other Project->Empty Qt Project
When we create a Empty Qt Project There is nothing in the Project explorer, and even the .pro file has nothing in it. So, we need to create a main.cpp file.
Step 2 – Right Click on Project -> Add New -> C++ -> C++ Source file -> Choose
And Give the name main.cpp file and press finish.
main.cpp
#include <QApplication>
#include <QMainWindow>
#include <QTabWidget>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QMainWindow *window = new QMainWindow();
window->setWindowTitle(QString::fromUtf8("MainWindow"));
window->resize(250, 250);
QWidget *centralWidget = new QWidget(window);
QTabWidget *tabs = new QTabWidget(centralWidget);
tabs->setFixedSize(245, 245);
tabs->addTab(new QWidget(),"TAB 1");
tabs->addTab(new QWidget(),"TAB 2");
window->setCentralWidget(centralWidget);
window->show();
return app.exec();
}
.pro file
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
SOURCES += \
main.cpp

Leave a Reply