Reputation: 5165
I want the central widget of my mainWindow
class to be a QTabWidget
. My plan is to create widgets that I want to put in the tabs as separate classes and add them to QTabWidget
class and add the QtabWidget
class itself as a central Widget to the mainWindow
class.
To do this, how must I declare my tabWidget class ?
Should it be :
class centralTab : public QMainWindow
{
}
or
class centralTab : public QDialog
{
}
Also, in the ctor, What should be used as the parent ?
Upvotes: 0
Views: 1568
Reputation: 18504
Just create QMainWindow
subclass:
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
//...
};
In constructor use addTab()
method::
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent)
{
QTabWidget *tabWidget = new QTabWidget(this);
//some settings
tabWidget->addTab(new QLabel("example1"), "General1");
tabWidget->addTab(new QLabel("example2"), "General2");
setCentralWidget(tabWidget);
}
Why QMainWindow
? Because only QMainWindow
has setCentralWidget()
method;
You can add different widgets and set also icon to every tab, QLabel
is just example.
Upvotes: 4