Results 1 to 6 of 6

Thread: How to replace a QWidget in a QDockWidget? (Qt 4.2.0-rc1)

  1. #1
    Join Date
    Sep 2006
    Location
    Asperg, Germany
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Question How to replace a QWidget in a QDockWidget? (Qt 4.2.0-rc1)

    A document shows its properties in an associated QDockWidget. In a MDI-Application this QDockWidget should be reused from each document. So that the QDockWidget will allways contain the properties of the active document.

    The properties of the document are stored in an XML-file. The XML-file is loaded into an object retrieved from class QTreeWidget using QDomDocument::setContent(QIODevice*, ...). Each document (MDI-Child) has now its own QTreeWidget populated with its properties. The parent of this QTreeWidges is the QDockWidget.

    To set the QTreeWidget into the QDockWidget the methode setWidget(QWidget*) is used. This works fine when loading several files. The properties of the last loaded file is shown.

    But when a previous file is activated (setWidget(...) is called with a QWidget which was previously set), the properties of the last loaded file are always shown on top of the QDockWidget. When enlarging the QDockWidgt the QTreeWidget on top is framed by small line and the QTreeWidget behind is resized as expected (s. screeshot).
    DockWidgetReplace.jpg
    Occures this behaviour in older versions of Qt too?
    Is there a way to remove the previously set QWidget from an QDockWidget?
    Should I try another way to find an adequate resolution?

    Any help appreciated
    Anton

    happy with: Qt4 Visual Studio 2005 Add-in - Plattform: Windows - Version: 4.5.3

  2. #2
    Join Date
    Jan 2006
    Location
    India
    Posts
    115
    Thanks
    3
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to replace a QWidget in a QDockWidget? (Qt 4.2.0-rc1)

    Reason behind such behaviour is that QDockWidget AFAIK is designed to handle one child at a time, and you are having many children.
    My advice, if you want to retain your current method, is that you re-parent the old (unused) QTreeWidget while setting a new QTreeWidget to QDockWidget.

  3. #3
    Join Date
    Sep 2006
    Location
    Asperg, Germany
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to replace a QWidget in a QDockWidget? (Qt 4.2.0-rc1)

    Dear yogeshm02

    Many thanks to You! It's unbelievable, getting a working solution to my problem in such a short time

    Following Your advice, I added three lines of code:

    Qt Code:
    1. void MainWindow::replaceDockEquipment(ParameterTree* equipment)
    2. {
    3. ParameterTree* old = qobject_cast<ParameterTree*>(dockWdgtEqmt->widget());
    4. if (equipment != old) {
    5. if (old)
    6. old->setParent(0); // in memorial yogeshm02 (Qt Center Forum)
    7.  
    8. equipment->setParent(dockWdgtEqmt);
    9. dockWdgtEqmt->setWidget(equipment);
    10. dockWdgtEqmt->update();
    11. }
    12. }
    To copy to clipboard, switch view to plain text mode 
    Anton

    happy with: Qt4 Visual Studio 2005 Add-in - Plattform: Windows - Version: 4.5.3

  4. #4
    Join Date
    Jan 2006
    Posts
    369
    Thanks
    14
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to replace a QWidget in a QDockWidget? (Qt 4.2.0-rc1)

    another option might be using QStackedWidget in the dock widget and changing the current widgets as you move along and deleting widgets when the tab is closed.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to replace a QWidget in a QDockWidget? (Qt 4.2.0-rc1)

    Instead of creating dozens of widgets, you might consider using one QTreeView and several models.

  6. #6
    Join Date
    Sep 2006
    Location
    Asperg, Germany
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Thumbs up Re: How to replace a QWidget in a QDockWidget? (Qt 4.2.0-rc1)

    Hi elcuco,
    Hi jacek,

    many thanks for Your advice.

    I'm not only a beginner in this forum, but also to Qt . I havn't any experience with QStackedWidgets (up to now) I hope this will change in the near future.

    A solution with one QTreeView and several models appears promising. I'll check them.
    Anton

    happy with: Qt4 Visual Studio 2005 Add-in - Plattform: Windows - Version: 4.5.3

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.