Results 1 to 4 of 4

Thread: Widget dragging in MDI app

  1. #1
    Join Date
    Jan 2007
    Location
    The Hague, The Netherlands
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Widget dragging in MDI app

    Funny behaviour of child widgets in MDI apps.

    MDI child widgets (unless you use editable widgets like QTextedit) are dragged in QWorkspace when you move the mouse with pressed left mouse button anywhere inside the widget. This prohibits drawing/measuring with the mouse inside the widget.

    Source code below compiles to what I mean.

    The MDI example in Qt examples/mainwindows has the same behaviour when the MDI child widget inherits QWidget instead of QTextEdit in the example.
    I use Qt 4.2.2. The problem is the same with Linux and Windows.

    Any suggestions to overcome this? Feels like a bug, but maybe it`s defined behaviour, and I should just change a windowsFlag somewhere?

    ================================
    Qt Code:
    1. #include <QtGui>
    2. class mdiChild:public QWidget
    3. {
    4. public:
    5. mdiChild():QWidget(){}
    6. };
    7.  
    8. class mainWindow:public QMainWindow
    9. {
    10. public:
    11. mainWindow():QMainWindow() {
    12. QWorkspace* workspace = new QWorkspace;
    13. setCentralWidget(workspace);
    14.  
    15. mdiChild *child = new mdiChild();
    16. workspace->addWindow(child);
    17. child->setGeometry(10,10,200,100);
    18. child->show();
    19. }
    20. };
    21.  
    22. int main(int argc, char *argv[])
    23. {
    24. QApplication app(argc, argv);
    25. mainWindow mainWin;
    26. mainWin.show();
    27. return app.exec();
    28. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Widget dragging in MDI app

    Moving the widget seems to be the default behaviour of the widget.
    To draw on the widget implement the mousepress, mousemove and mouse release events... and override the paintevent to draw inside the widget...


    check the code attached...
    Attached Files Attached Files

  3. #3
    Join Date
    Jan 2007
    Location
    The Hague, The Netherlands
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Widget dragging in MDI app

    Quote Originally Posted by aamer4yu View Post
    Moving the widget seems to be the default behaviour of the widget.
    To draw on the widget implement the mousepress, mousemove and mouse release events... and override the paintevent to draw inside the widget...
    Yes, that sure a way to prevent the widget from moving, thanks.
    But I don` understand why default widget behaviour in QWorkspace is different from standard behaviour.
    For widgets like QStatusBar inside a MdiChild it is a bit freaky, to reimplement QStatusBar and override mouse events, just to prevent the MdiChild from accidently moving.

  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: Widget dragging in MDI app

    If I understand the concept correctly, then you only need to reimplement those events for direct children of the workspace, so if you don't use floating QStatusBar widgets, you won't need to touch them. Anyway I think that's not needed as well, as you can probably do everything by reimplementing mouse events in QWorkspace (there probably is an event filter installed somewhere, so even that might not be necessary).

Similar Threads

  1. Replies: 1
    Last Post: 6th November 2006, 00:50
  2. Pin/Unpin Dock Widget
    By charlesD in forum Newbie
    Replies: 1
    Last Post: 21st June 2006, 07:57
  3. Replies: 4
    Last Post: 24th March 2006, 23:50
  4. Forwarding mouse events to another widget.
    By yogeshm02 in forum Qt Programming
    Replies: 8
    Last Post: 28th February 2006, 14:25
  5. [Qt 4.1.0] Split a widget on demand
    By Townk in forum Qt Programming
    Replies: 3
    Last Post: 17th February 2006, 15:16

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.