Results 1 to 8 of 8

Thread: QMdiArea : moving tab issue.

  1. #1
    Join Date
    Jan 2011
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QMdiArea : moving tab issue.

    Hello everyone,

    While designing an application with mdiArea and its tabbed view mode, i have an issue if i set its QTabBar movable : the connexions are not updating to the correct mdi window when moved. If you move the tabs, it will no more focus the correct window.

    I'm surely using it wrong, but we never know if it's a bug (or a feature ). I found the same behavior under Qt4.5 (linux), and Qt4.7.1 (windows)

    Here's a quick and dirty made example

    Qt Code:
    1. #include <QApplication>
    2. #include <QtGui>
    3.  
    4. int main(int argc, char* argv[])
    5. {
    6. QApplication app(argc, argv);
    7.  
    8. QMdiArea *mdiArea = new QMdiArea();
    9. mdiArea->setViewMode(QMdiArea::TabbedView);
    10. mdiArea->findChild<QTabBar*>()->setMovable(true);
    11.  
    12. QMdiSubWindow *firstTab = mdiArea->addSubWindow(new QTextEdit("i'm the first tab"));
    13. firstTab->setWindowTitle("first tab");
    14. QMdiSubWindow *secondTab = mdiArea->addSubWindow(new QTextEdit("i'm the second tab"));
    15. secondTab->setWindowTitle("second tab");
    16.  
    17. mdiArea->show();
    18.  
    19. return app.exec();
    20. }
    To copy to clipboard, switch view to plain text mode 

    Thanks for your help, have a good day,

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QMdiArea : moving tab issue.

    Without dwelling to long in your code, the follwing is not clear to me:
    Qt Code:
    1. mdiArea->findChild<QTabBar*>()->setMovable(true);
    To copy to clipboard, switch view to plain text mode 
    You call this right after creating the MDI area, when it has no children yet.. actually I would say this line should crash, since the returned pointer should be null...
    You should call this after you have added your children to the MDI.
    Even if you would call this line in the right place have a look at the docs about it:
    If there is more than one child matching the search, the most direct ancestor is returned. If there are several direct ancestors, it is undefined which one will be returned. In that case, findChildren() should be used.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Jan 2011
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QMdiArea : moving tab issue.

    When the viewMode is set to tabbed view, a MDI area always has a QTabBar widget.

    Qt Code:
    1. int main(int argc, char* argv[])
    2. {
    3. QApplication app(argc, argv);
    4.  
    5. QMdiArea *mdiArea = new QMdiArea();
    6. mdiArea->setViewMode(QMdiArea::TabbedView);
    7. mdiArea->dumpObjectTree();
    8. mdiArea->show();
    9.  
    10. return app.exec();
    11. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. QMdiArea::
    2. QWidget::qt_scrollarea_hcontainer
    3. QWidget::qt_scrollarea_vcontainer
    4. QTabBar:: // <= Here
    To copy to clipboard, switch view to plain text mode 

    And, as i can see on the doc, there's no other way to get access to its QTabBar widget.
    Last edited by Satan2K; 9th January 2011 at 20:12.

  4. #4
    Join Date
    Jan 2011
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QMdiArea : moving tab issue.

    So is it the correct behavior, or should i report it as a bug?

    In the meantime, i changed completely the part using QMdiArea to an new object inheriting from QTabWidget, and i destroy its child widget when a tab is requested to be removed. (tabCloseRequested(int) to a custom slot)

    tabObject->widget(index)->deleteLater();
    tabObject->removeTab(index);

  5. #5
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QMdiArea : moving tab issue.

    So is it the correct behavior, or should i report it as a bug?
    I didn't have time to test this, so I don't know.
    Hopefully someone else can comment on this too.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  6. #6
    Join Date
    Jan 2011
    Posts
    1
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Thumbs up Re: QMdiArea : moving tab issue.

    Quote Originally Posted by Satan2K View Post
    In the meantime, i changed completely the part using QMdiArea to an new object inheriting from QTabWidget, and i destroy its child widget when a tab is requested to be removed. (tabCloseRequested(int) to a custom slot)

    tabObject->widget(index)->deleteLater();
    tabObject->removeTab(index);
    Thanks a lot for your question. I've tried to make my own mdi-style widget with QTabBar but have many problems with destruction. First of this two lines is exactly what I need.

    About QMdiArea. Since you hacked it to find mysterious QTabBar inside, you can't be sure about stable behavior in future. So I think this situation is a feature. (Or feature-lack in QMdiArea interface )

  7. #7
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: QMdiArea : moving tab issue.

    Quote Originally Posted by Satan2K View Post
    So is it the correct behavior, or should i report it as a bug?
    Looks like a fix has been submitted for review: link

  8. #8
    Join Date
    Jan 2011
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QMdiArea : moving tab issue.

    haha great, so I don't have to worry about reporting it. Thanks

    Thanks a lot for your question. I've tried to make my own mdi-style widget with QTabBar but have many problems with destruction. First of this two lines is exactly what I need.
    It's quite simple if you inherit from a QTabWidget. Here's the test example i quickly designed.

    Qt Code:
    1. class UI_TabWidget : public QTabWidget
    2. {
    3. Q_OBJECT
    4.  
    5. public :
    6. UI_TabWidget(QWidget *pParent = 0);
    7. void openTab();
    8.  
    9. private slots :
    10. void closeTab(int iTabIndex);
    11. };
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. UI_TabWidget::UI_TabWidget(QWidget *pParent) : QTabWidget(pParent)
    2. {
    3. this->setMovable(true);
    4. this->setTabsClosable(true);
    5. QObject::connect(this, SIGNAL(tabCloseRequested(int)), this, SLOT(closeTab(int)));
    6. }
    7.  
    8. void UI_TabWidget::openTab()
    9. {
    10. //Here's a quick test widget
    11. QTextEdit *pTextEdit = new TextEdit();
    12. //Attaching it to a new tab
    13. this->addTab(pTextEdit, "test");
    14. }
    15.  
    16. void UI_TabWidget::closeTab(int iTabIndex)
    17. {
    18. this->widget(iTabIndex)->deleteLater();
    19. this->removeTab(iTabIndex);
    20. }
    To copy to clipboard, switch view to plain text mode 

    Feel free to attach a custom made widget in openTab too, and you'll be able to access its member with
    Qt Code:
    1. myCustomWidget *pWidget = dynamic_cast <myCustomWidget*>(this->widget(iTabIndex));
    To copy to clipboard, switch view to plain text mode 

    Then you'll be able to make custom states to check before closing
    Qt Code:
    1. if (!pWidget->m_bAllowedToClose)
    2. //...
    To copy to clipboard, switch view to plain text mode 

    Have fun ;-)

Similar Threads

  1. Replies: 0
    Last Post: 24th May 2010, 12:19
  2. QwtPlot3d and QMdiArea
    By YaK in forum Qwt
    Replies: 0
    Last Post: 17th March 2010, 04:53
  3. QMdiArea/SubWindow issue...
    By b1 in forum Qt Programming
    Replies: 3
    Last Post: 2nd September 2009, 08:22
  4. QMdiArea
    By Programm3r in forum Qt Programming
    Replies: 0
    Last Post: 4th May 2009, 14:25
  5. How to set QMdiArea::WindowOrder ?
    By akobor in forum Qt Programming
    Replies: 1
    Last Post: 10th January 2008, 15:04

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.