Results 1 to 1 of 1

Thread: Force dragging a QDockWidget

  1. #1
    Join Date
    Oct 2014
    Posts
    81
    Thanks
    20
    Thanked 9 Times in 9 Posts
    Qt products
    Qt5
    Platforms
    Windows
    Wiki edits
    7

    Default Re: Force dragging a QDockWidget

    Hello.
    I'm trying to force a floating dock widget to enter 'mouse drag mode,' when you drag a widget by the title bar of the window.

    I've looked at the source for QDockWidget ("qdockwidget.cpp") and identified the conditions necessary for it to start the dragging mode: https://qt.gitorious.org/qt/qtbase/s...idget.cpp#L916
    It catches a QEvent::NonClientAreaMousePressEvent event, and if it's inside the title area the floating dock widget 'dragging mode' is started.

    I'm using the following to synthesize the event. "DetachableDock" inherits QDockWidget:

    Qt Code:
    1. void DetachableDock::requestGrab()
    2. {
    3. // Center the dock widget window on the cursor.
    4.  
    5. int centerTitleX = frameGeometry().width() / 2;
    6. int centerTitleY = ( frameGeometry().height() - geometry().height() ) / 2;
    7.  
    8. QPoint centerTitlePos = QCursor::pos() - QPoint( centerTitleX, centerTitleY );
    9. move( centerTitlePos );
    10.  
    11. // Synthesize the mouse press event.
    12.  
    13. QMouseEvent grabEvent( QEvent::NonClientAreaMouseButtonPress, QPoint( centerTitleX, -centerTitleY ), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier );
    14. QApplication::sendEvent( this, &grabEvent );
    15.  
    16. qDebug() << "EVENT SENT";
    17. }
    To copy to clipboard, switch view to plain text mode 

    This is called when I click on a button. Before calling this I synthesize a "mouse release" event for the button. The window remains unselected and undragabble. If I move the cursor it doesn't drag it.
    I've subclassed QDockWidget with this "DetachableDock" class. I reimplemented the QWidget::event( QEvent* event ) function and I can certify that this NonClientAreaMousePressEvent is being received by the widget.


    Added after 54 minutes:


    Here's the project folder.
    I appreciate if someone can tell me what it's missing to be able to fully enter that dock widget dragging mode with only synthesized events.
    Attached Files Attached Files
    Last edited by Kryzon; 7th January 2015 at 10:51.

Similar Threads

  1. QDockWidget inside QDockWidget
    By mqt in forum Qt Programming
    Replies: 3
    Last Post: 1st July 2013, 12:57
  2. Problem in dragging and move QDockWidget
    By stilgar in forum Qt Programming
    Replies: 1
    Last Post: 18th April 2012, 10:33
  3. Replies: 1
    Last Post: 7th December 2010, 21:46
  4. dragging
    By mickey in forum Newbie
    Replies: 1
    Last Post: 25th July 2006, 14:05
  5. dragging
    By mickey in forum Newbie
    Replies: 5
    Last Post: 11th March 2006, 00:26

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.