PDA

View Full Version : Adding a widget to a QTabWidget



alitoh
2nd November 2011, 19:29
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?


m_pTopLayout = new QVBoxLayout(this);

m_pTabWidget = new QTabWidget(this);
m_pTopLayout->addWidget(m_pTabWidget);

m_pRightCB = new QSSRoundedCombo(this);
m_pLeftCB = new QSSRoundedCombo(this);
m_pComboLayout = new QHBoxLayout(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");

ChrisW67
3rd November 2011, 06:00
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.

rivci
8th November 2011, 06:57
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?


m_pTopLayout = new QVBoxLayout(this);

m_pTabWidget = new QTabWidget(this);
m_pTopLayout->addWidget(m_pTabWidget);

m_pRightCB = new QSSRoundedCombo(this);
m_pLeftCB = new QSSRoundedCombo(this);
m_pComboLayout = new QHBoxLayout(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?


m_pTabWidget->setCurrentWidget(pHistogramWidget);