Adding a widget to a QTabWidget
I have a QTabWidget and I want to show different widgets according to the selected tab.
I thought doing a m_tabwidget->addTab(pWidgetIWantToShow, "Title") was the way to go,but albeit the tab with the "Title" title is being created, nothing is being displayed.
As it is only one tab so far, itshould set itself to default automatically (as I understood it, at least).
Am I doing something wrong? Missing something maybe?
Code:
m_pTopLayout->addWidget(m_pTabWidget);
m_pRightCB = new QSSRoundedCombo(this);
m_pLeftCB = new QSSRoundedCombo(this);
m_pComboLayout->addWidget(m_pLeftCB);
m_pComboLayout->addWidget(m_pRightCB);
m_pTopLayout->addLayout(m_pComboLayout);
m_pHistogramWidget = new HistogramWidget();
m_pTabWidget->addTab(pHistogramWidget , "Histogram");
Re: Adding a widget to a QTabWidget
Where is your code that puts anything on the HistogramWidget? If there is nothing on this widget then you will see nothing in the tab widget.
You can call QTabWidget::setCurrentWidget() or QTabWidget::setCurrentIndex() (with the index returned by addTab()) to ensure the newly added widget is displayed.
Re: Adding a widget to a QTabWidget
Quote:
Originally Posted by
alitoh
I have a QTabWidget and I want to show different widgets according to the selected tab.
I thought doing a m_tabwidget->addTab(pWidgetIWantToShow, "Title") was the way to go,but albeit the tab with the "Title" title is being created, nothing is being displayed.
As it is only one tab so far, itshould set itself to default automatically (as I understood it, at least).
Am I doing something wrong? Missing something maybe?
Code:
m_pTopLayout->addWidget(m_pTabWidget);
m_pRightCB = new QSSRoundedCombo(this);
m_pLeftCB = new QSSRoundedCombo(this);
m_pComboLayout->addWidget(m_pLeftCB);
m_pComboLayout->addWidget(m_pRightCB);
m_pTopLayout->addLayout(m_pComboLayout);
m_pHistogramWidget = new HistogramWidget();
m_pTabWidget->addTab(pHistogramWidget , "Histogram");
have u try this?
Code:
m_pTabWidget->setCurrentWidget(pHistogramWidget);