Results 1 to 5 of 5

Thread: resize qdockwidget through embedded widget

  1. #1
    Join Date
    Apr 2009
    Posts
    206
    Thanks
    34
    Thanked 2 Times in 2 Posts

    Default resize qdockwidget through embedded widget

    Hello friends,

    I have a question. I add a QWidget into a QDockwidget. How can I resize(the width) from dockwidget, when I resize the QWidget in it??

    Yours,

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: resize qdockwidget through embedded widget

    Your question is unclear: do you want to resize the dock widget and have the contents resize, or do you want to resize the dock widget to fit the content you put in it.
    "We can't solve problems by using the same kind of thinking we used when we created them." -- Einstein
    If you are posting code then please use [code] [/code] tags around it - makes addressing the problem easier.

  3. #3
    Join Date
    Apr 2009
    Posts
    206
    Thanks
    34
    Thanked 2 Times in 2 Posts

    Default Re: resize qdockwidget through embedded widget

    When I resize the embedded widget in its EnterEvent I resize it but the QDockwidget, which operate here as container for my widget dont resize it self.Thats my point.

    Yours,

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: resize qdockwidget through embedded widget

    The size of the dock widget container resizes to accommodate its content when that content imposes a constraint that would require it to: in all other cases the container sets the size of its content. The constraint will come from the contained widget's layout, minimum and maximum size, size hint, and size policy. Your best bet is to give your contained widget's layout a QLayout::SetFixedSize size constraint.

    Qt Code:
    1. #include <QtGui>
    2. #include <QDebug>
    3.  
    4.  
    5. class MorphingWidget: public QWidget {
    6. Q_OBJECT
    7. public:
    8. MorphingWidget(QWidget *p = 0): QWidget(p) {
    9. QVBoxLayout *layout = new QVBoxLayout(this);
    10. layout->setSizeConstraint(QLayout::QLayout::SetFixedSize); // try with/without this
    11.  
    12. top = new QPushButton("Top Button", this);
    13. layout->addWidget(top);
    14.  
    15. bottom = new QPushButton("Bottom Button Long", this);
    16. bottom->hide();
    17. layout->addWidget(bottom);
    18. }
    19. protected:
    20. void enterEvent ( QEvent * event ) { bottom->show(); QWidget::enterEvent(event); }
    21. void leaveEvent ( QEvent * event ) { bottom->hide(); QWidget::leaveEvent(event); }
    22. private:
    23. QPushButton *bottom;
    24. };
    25.  
    26. class MainWindow: public QMainWindow {
    27. Q_OBJECT
    28. public:
    29. MainWindow(QWidget *p = 0): QMainWindow(p) {
    30. QWidget *central = new QTextEdit(this);
    31. setCentralWidget(central);
    32.  
    33. QDockWidget *dock = new QDockWidget(this);
    34. dock->setWidget(new MorphingWidget(this));
    35. addDockWidget(Qt::RightDockWidgetArea, dock);
    36.  
    37. resize(640, 480);
    38. }
    39. };
    40.  
    41. int main(int argc, char *argv[])
    42. {
    43. QApplication app(argc, argv);
    44. MainWindow m;
    45. m.show();
    46. return app.exec();
    47. }
    48. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Apr 2009
    Posts
    206
    Thanks
    34
    Thanked 2 Times in 2 Posts

    Default Re: resize qdockwidget through embedded widget

    Great thanks for your help,

    in my situation I am also subclass QWidget.I paint some rects on the widget, and in enter event I change the size of the rects, so I make a repaint, resize the widget and the Dockwidget make nothing. I dont have any layout in there.

    Maybe I have to give a pointer of the Dockwidget to the childwidget and make a setFixedWidth or so!!

    Yours,

Similar Threads

  1. Resize a QDockWidget ? (Width)
    By Selven in forum Qt Programming
    Replies: 5
    Last Post: 29th April 2012, 13:54
  2. resize QDockWidget
    By Gh0str1d3r in forum Qt Programming
    Replies: 0
    Last Post: 27th August 2010, 11:18
  3. Qt 4.4 QDockWidget resize problem
    By MarkSutton in forum Qt Tools
    Replies: 2
    Last Post: 27th September 2008, 08:55
  4. Replies: 5
    Last Post: 12th September 2008, 23:13
  5. How to get a QDockWidget to auto resize?
    By bitChanger in forum Qt Programming
    Replies: 4
    Last Post: 6th January 2006, 16:10

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.