开发者

Quick question about using the QTabWidget 'addTab' function

开发者 https://www.devze.com 2023-03-20 05:07 出处:网络
Hopefully a very quick question. In one of my functions I want to generate an \'x\' number of tabs for a QTabWidget during run-time (\'x\' provided by user). I know I have to use the addTab function f

Hopefully a very quick question. In one of my functions I want to generate an 'x' number of tabs for a QTabWidget during run-time ('x' provided by user). I know I have to use the addTab function for the QTabWidget (correct me if I'm wrong), but I am unsure as to how I am supposed to use it. The qt documentation was unclear to me.

I have tried the following command to add only 1 tab as a test, but it caused the program to crash:

ui->checkBoxTabArea->addTab(ui->checkBoxTabArea,"tab2");

Since I am obviously wrong, can somebody help me use this function? I feel like I am just passing the wrong arguments to addTab.

Edit: checkBoxTabArea already has 1 tab when the program starts up (if 开发者_如何学Gothis is any help).


If you take a look at the documentation, the addTab function says this :

int QTabWidget::addTab ( QWidget * page, const QString & label )

Adds a tab with the given page and label to the tab widget, and returns the index of the tab in the tab bar.

So the argument you pass should not be the TabWidget you want to add the tab to, rather it should be the widget you want to add as the tab.

What you should do is something like :

QLabel *myLabel = new QLabel("Hello World", this);
ui->checkBoxTabArea->addTab(myLabel, "My Label Tab");

This will add a single tab to the tab widget, which contains myLabel.

0

精彩评论

暂无评论...
验证码 换一张
取 消