Results 1 to 5 of 5

Thread: odd failure while adding custom widgets to QDockWidget

  1. #1
    Join Date
    Nov 2008
    Posts
    5

    Default odd failure while adding custom widgets to QDockWidget

    I want to add several widgets to a single dockwidget.
    As the QDockWidget owns no "addWidget" function, I managed to add a widgetForDock widget to it using "setWidget" function, and make other widgets children of the widgetForDock.

    eg:
    Qt Code:
    1. dockWidget->setWidget(widgetForDock);
    To copy to clipboard, switch view to plain text mode 

    It works well, when I make it through toward the Qt widgets, such as QLineEdit and QGroupBox. However, when I add my own object of class HistogramView, derived from QWidget, it fails to show.

    eg: fail
    Qt Code:
    1. QVBoxLayout *layout = new QVBoxLayout(widgetForDock);
    2. HistogramView *histView = new HistogramView();
    3. layout->addWidget(histView);
    4.  
    5. class HistogramView : public QWidget
    6. {
    7. ...
    8. public:
    9. HistogramPlotter *histPlotter;
    10. QWidget *widget;
    11. }
    To copy to clipboard, switch view to plain text mode 

    The even odder thing is that, when I add the object histView itselft to the dockWidget, it fails, while the public members (histPlotter and widget) are added to it, it works well!

    eg: works!
    Qt Code:
    1. layout->addWidget(histView->histPlotter);
    2. layout->addWidget(histView->widget);
    To copy to clipboard, switch view to plain text mode 
    The HistogramPlotter is a cumter widget, also derived from the QWidget, just as its owner object do.
    Last edited by jpn; 4th December 2008 at 19:45. Reason: missing [code] tags

  2. #2
    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: odd failure while adding custom widgets to QDockWidget

    Does this custom widget work OK if you add it to a normal widget? Could you post the HistogramView::HistogramView() code?

  3. #3
    Join Date
    Nov 2008
    Posts
    5

    Default Re: odd failure while adding custom widgets to QDockWidget

    Thanks a lot for your care.
    I've tried to put HistogramView's object into QGroupBox's layout, and it follows the same problem:
    when HistogramView's object itself added in , it fails, while the public member added in , it works well !

    Qt Code:
    1. class HistogramView : public QWidget
    2. {
    3. Q_OBJECT
    4. public:
    5. HistogramView(QWidget *parent = 0);
    6. HistogramView(const QImage &image, QWidget *parent = 0);
    7. signals:
    8. ...
    9. private slots:
    10. ...
    11. public:
    12. HistogramPlotter *histPlotter;
    13. QWidget *widget;
    14. ...
    15. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jpn; 4th December 2008 at 19:47. Reason: missing [code] tags

  4. #4
    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: odd failure while adding custom widgets to QDockWidget

    What do you do with "parent" in the constructor?

  5. #5
    Join Date
    Nov 2008
    Posts
    5

    Default Re: odd failure while adding custom widgets to QDockWidget

    it's passed to the object's parent, QWidget, for initialization

Similar Threads

  1. Replies: 2
    Last Post: 16th May 2008, 14:39
  2. picking geometry in qt custom widgets
    By notsonerdysunny in forum Qt Programming
    Replies: 2
    Last Post: 17th July 2007, 23:01

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.