Results 1 to 4 of 4

Thread: Dockable widgets: drag by body, not by header

  1. #1
    Join Date
    Mar 2012
    Location
    Moscow
    Posts
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default Dockable widgets: drag by body, not by header

    Hello all.

    I have this problem today. I want to drag QDockWidget objects inside QMainWindow catching them by body, but no by header. There are no dock widgets headers in application I written.

    I tried to solve this problem putting body widget in the header entirely. But docking behaviour was really bad in this case...

    Does anyone know the solution?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Dockable widgets: drag by body, not by header

    It should be possible to do what you want by intercepting mouse events and translating them so that the widget thinks it is dragged by the header.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Mar 2012
    Location
    Moscow
    Posts
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Dockable widgets: drag by body, not by header

    Thanks for the reply,
    eventually, I found the solution: remove unnecessary conditions from QDockWidgetPrivate class (mousePressEvent) and rebuild QtGui.

    Qt Code:
    1. bool QDockWidgetPrivate::mousePressEvent(QMouseEvent *event)
    2. {
    3. #if !defined(QT_NO_MAINWINDOW)
    4.  
    5. QDockWidgetLayout *dwLayout
    6. = qobject_cast<QDockWidgetLayout*>(layout);
    7.  
    8. if (!dwLayout->nativeWindowDeco()) {
    9. QRect titleArea = dwLayout->titleArea();
    10.  
    11. if (event->button() != Qt::LeftButton ||
    12. !titleArea.contains(event->pos()) ||
    13. // check if the tool window is movable... do nothing if it
    14. // is not (but allow moving if the window is floating)
    15. (!hasFeature(this, QDockWidget::DockWidgetMovable) && !q->isFloating()) ||
    16. qobject_cast<QMainWindow*>(parent) == 0 ||
    17. isAnimating() || state != 0) {
    18. return false;
    19. }
    20.  
    21. initDrag(event->pos(), false);
    22.  
    23. if (state)
    24. state->ctrlDrag = hasFeature(this, QDockWidget::DockWidgetFloatable) && event->modifiers() & Qt::ControlModifier;
    25.  
    26. return true;
    27. }
    28.  
    29. #endif // !defined(QT_NO_MAINWINDOW)
    30. return false;
    31. }
    To copy to clipboard, switch view to plain text mode 

    Line number 13 above.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Dockable widgets: drag by body, not by header

    Quote Originally Posted by BigSmartFastAndrey View Post
    Thanks for the reply,
    eventually, I found the solution: remove unnecessary conditions from QDockWidgetPrivate class (mousePressEvent) and rebuild QtGui.
    That's not really a solution unless you intend to break all programs using Qt on your system and some programs of everyone's using your application.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 2
    Last Post: 31st July 2009, 09:18
  2. 'Alt+Tab' Operation for QT Apps containg dockable widgets
    By nileshsince1980 in forum Qt Programming
    Replies: 1
    Last Post: 20th May 2009, 09:05
  3. How to get correct header with custom made widgets?
    By Arthur in forum Qt Programming
    Replies: 3
    Last Post: 26th April 2007, 17:07
  4. Replies: 0
    Last Post: 10th November 2006, 13:46
  5. drag and frop widgets
    By sreedhar in forum Qt Programming
    Replies: 2
    Last Post: 16th May 2006, 17:13

Tags for this Thread

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.