Results 1 to 4 of 4

Thread: how to detach Tab page from QTabWidget?

  1. #1
    Join Date
    May 2006
    Location
    Bangalore,India
    Posts
    235
    Thanks
    7
    Thanked 25 Times in 24 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Question how to detach Tab page from QTabWidget?

    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?

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: how to detach Tab page from QTabWidget?

    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.
    J-P Nurmi

  3. #3
    Join Date
    Oct 2010
    Posts
    13
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to detach Tab page from QTabWidget?

    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!

  4. #4
    Join Date
    May 2012
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to detach Tab page from QTabWidget?

    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:

    Qt Code:
    1. int indexTab; // the index into the QTabBar you want to remove
    2. QWidget* pWidget; // the widget in the QStackedWidget that corresponds to indexTab
    3. QPoint posGlobal; // where you want the detached widget's new window to go
    4.  
    5. m_pStackedWidget->removeWidget(pWidget);
    6. m_pTabBar->removeTab(indexTab);
    7. pWidget->setParent(NULL, Qt::Tool);
    8. pWidget->move(posGlobal);
    9. pWidget->show();
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Corner widget in QTabWidget doesn't show up
    By ePharaoh in forum Qt Programming
    Replies: 2
    Last Post: 6th April 2006, 17:02
  2. Change the text color tab page
    By gtthang in forum Qt Programming
    Replies: 4
    Last Post: 18th February 2006, 17:38
  3. Customize QTabBar or QTabWidget
    By gtthang in forum Qt Programming
    Replies: 3
    Last Post: 15th February 2006, 08:39

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.