Results 1 to 3 of 3

Thread: Dock Widget Custom Resizing?

  1. #1
    Join Date
    Apr 2010
    Posts
    152
    Thanks
    5
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Dock Widget Custom Resizing?

    Is it possible to make the resizing of a QDockWidget happen after mouse release? Same as opaque sizing of the QSplitter?

    Thanks.

  2. #2
    Join Date
    Apr 2010
    Posts
    152
    Thanks
    5
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Dock Widget Custom Resizing?

    Is there a style-sheet attribute I need to set?

  3. #3
    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: Dock Widget Custom Resizing?

    QSplitter uses the opaque resize flag to alter its behaviour to use a rubber band and not propagate resizes to the child widgets until the mouse is released.
    As far as I can tell when the QDockwidget is floating resizing is handled by the window manager and not within Qt control.
    When the QDockWidget is docked its resize behaviour would be controlled by QMainWindow layout and any splitters it may use.

    If the content of the dock widget is expensive to redraw then you may be able to fake it by suppressing updates until some short time after the last resize event.
    Qt Code:
    1. #include <QtGui>
    2.  
    3. class Widget: public QWidget {
    4. Q_OBJECT
    5. public:
    6. Widget(QWidget *p = 0): QWidget(p) {
    7. m_resizeTimer = new QTimer(this);
    8. m_resizeTimer->setSingleShot(true);
    9. m_resizeTimer->setInterval(250); // how many milliseconds after last resize event do we draw
    10. connect(m_resizeTimer, SIGNAL(timeout()), SLOT(releaseResize()));
    11. setStyleSheet(" Widget { background-color: blue; } ");
    12. }
    13. protected:
    14. void resizeEvent(QResizeEvent * event) {
    15. m_resizeTimer->start(); // start idle timer or restart running timer
    16. setUpdatesEnabled(false);
    17. QWidget::resizeEvent(event); // in case it is doing things that still need to happen
    18. }
    19.  
    20. private slots:
    21. void releaseResize() {
    22. setUpdatesEnabled(true);
    23. }
    24.  
    25. private:
    26. QTimer *m_resizeTimer;
    27. };
    28.  
    29. int main(int argc, char **argv){
    30. QApplication app(argc, argv);
    31. Widget w;
    32. w.resize(320, 240);
    33. w.show();
    34. return app.exec();
    35. }
    36. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 

    Or you could set a flag on the first resizeEvent(). Your paintEvent() should check the flag and draw something cheap if it is set, i.e. during resize. When the timer goes off reset the flag and call update() to redraw using the expensive version of paintEvent().
    Last edited by ChrisW67; 3rd April 2014 at 02:36.

Similar Threads

  1. How can I use QX11Info to make a custom dock bar. (like KDE)
    By TheBigOnion in forum Qt Programming
    Replies: 1
    Last Post: 22nd March 2012, 01:41
  2. create dock widget from some other widget
    By Onanymous in forum Qt Programming
    Replies: 1
    Last Post: 16th December 2011, 15:22
  3. Dock resizing when move another area [resolved]
    By castors33 in forum Qt Programming
    Replies: 1
    Last Post: 13th June 2011, 20:59
  4. resizing events of a custom widget in a layout
    By Rooster in forum Qt Programming
    Replies: 7
    Last Post: 16th February 2008, 10:52
  5. Pin/Unpin Dock Widget
    By charlesD in forum Newbie
    Replies: 1
    Last Post: 21st June 2006, 06:57

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.