Adding button to QTabWidget tabs
-
wrote on 18 Dec 2012, 08:22 last edited by
Hi everyone,
I have created a QTabWidget and it's tab count changing dynamically when a signal is triggerd. I have add tabs like@
QWidget *centralWidget = new QWidget();
ui->tabWidget->addTab(centralWidget,client->peerAddress().toString());
@
Everything is okey by now, but the problem is i want to add button to this tabs/centralWidget.Is there anyway to do it?
Thanks in advance.
-
wrote on 18 Dec 2012, 10:14 last edited by
Hi,
if you want to add a button on a specific tab (e.g. a close tab button), you can use "setTabButton()":http://qt-project.org/doc/qt-4.8/qtabbar.html#setTabButton on the tab bar.
if you want to add a button to the tab widget itself (e.g. an add tab button), I think "setCornerWidget()":http://qt-project.org/doc/qt-4.8/qtabwidget.html#setCornerWidget is what you are searching.
-
wrote on 18 Dec 2012, 10:21 last edited by
Both "setTabButton()" and "setCornerWidget()" is not what i want. I want that button to inside the "tab" not the tab header section. In the tab. For example, I have 5 tabs and i select the third tab, i want to see this button inside this particular tab.
-
wrote on 18 Dec 2012, 10:36 last edited by
You mean something like that:
@
class MyPage : public QWidget
{
void addButton(QPushButton* button);
void setContents(QWidget* widget);
};MyPage *page = new MyPage;
QWidget *centralWidget = new QWidget;page->setContents(centralWidget);
page->addButton(new QPushButton);ui->tabWidget->addTab(page, ,client->peerAddress().toString());
@ -
wrote on 18 Dec 2012, 11:06 last edited by
Let me explain it with this picture
-
wrote on 18 Dec 2012, 11:12 last edited by
Ok. That's what I tried to say with my piece of code :)
So you just have to create a base class for all your tabs, like the one in my previous post.
If you want to force your QTabWidget to use it only, you will have to sub-class QTabWidget.
-
wrote on 18 Dec 2012, 11:13 last edited by
Nevermind.
-
wrote on 18 Dec 2012, 11:16 last edited by
Thank you tilsitt !
I am going to try it and post the result. -
wrote on 4 May 2013, 06:08 last edited by
In the GUI right click QTabWidget and select add page :)
-
wrote on 13 May 2018, 07:12 last edited by
Dear Thehillmisu,
I have the same problem. I would like to add a QChart to a tab in tabWidget. I came so long that I can show it in main window using following but I don't know how to access to the tabWidget itself:ui->setupUi(this);
this->setCentralWidget(chartView);Thanks in advance!
-
Hi everyone,
I have created a QTabWidget and it's tab count changing dynamically when a signal is triggerd. I have add tabs like@
QWidget *centralWidget = new QWidget();
ui->tabWidget->addTab(centralWidget,client->peerAddress().toString());
@
Everything is okey by now, but the problem is i want to add button to this tabs/centralWidget.Is there anyway to do it?
Thanks in advance.
wrote on 13 May 2018, 07:24 last edited byDear Thehillmisu,
I have the same problem. I would like to add a QChart to a tab in tabWidget. I came so long that I can show it in main window using following but I don't know how to access to the tabWidget itself:ui->setupUi(this);
this->setCentralWidget(chartView);Thanks in advance!