PDA

View Full Version : how to detach Tab page from QTabWidget?



rajesh
14th July 2006, 07:59
how to detach Tab page from QTabWidget?
I implemented detach tab pages using a button click “Detach“. Now I want to detach using drag Tab of tabwidget.
Any idea how to do that?

jpn
14th July 2006, 08:15
Override mouseMoveEvent (or use an event filter) and detach after the user has moved the mouse long enough range. You will receive mouse move events only when mouse button is pressed (unless mouse tracking has been set) so it is enough just to catch mouse movements. If you find it hard to find out the range, you may also catch mouse press events to get the pressing point.

SKolaMunn
7th February 2011, 22:25
Hi Rajesh,

I was trying to write code to detach a tab widget and view it in a seperate dialog and something is not working. My Google search led me here and I was hoping you could help me. Here is my code for my detach function:

void MainWindow::detachGraphicsTab()
{
int index = pTabControl->currentIndex();
QString title = pTabControl->tabText(index);
QWidget* tabPage = pTabControl->widget(index);
QString tooltiptest = tabPage->toolTip();
pTabControl->removeTab(index);

QDialog* dlg = new QDialog(this);
dlg->setWindowTitle(title);

QHBoxLayout* pMainLay = new QHBoxLayout;
QPushButton* test = new QPushButton("TEST");

pMainLay->addWidget(test);
pMainLay->addWidget(tabPage);
dlg->setLayout(pMainLay);
dlg->show();

QString tooltiptest2 = tabPage->toolTip();
}

I feel like I must be missing something really silly. I know that the tabPage widget is the correct widget (I set a tooltip in the function where the tab widget is originally generated and I get it back in this function - tooltiptest and tooltiptest2 - and both strings are correct), the tab is being removed, and the new dialog opened with the correct title text and "TEST" button, but that's it. Any suggestions would be greatly appreciated! I realize this original post is from years ago, so I will be sure to try somewhere else next, but figured I'd give this a shot first.

Thanks!

DanBrakeley
30th May 2012, 16:20
First off, I'm using a QStackedWidget and a QTabBar, and not a QTabWidget. I'm not familiar with QTabWidget, but I'm assuming you can use the same idea. Here's how I am doing it:


int indexTab; // the index into the QTabBar you want to remove
QWidget* pWidget; // the widget in the QStackedWidget that corresponds to indexTab
QPoint posGlobal; // where you want the detached widget's new window to go

m_pStackedWidget->removeWidget(pWidget);
m_pTabBar->removeTab(indexTab);
pWidget->setParent(NULL, Qt::Tool);
pWidget->move(posGlobal);
pWidget->show();