Results 1 to 3 of 3

Thread: QMdiSubWindow Questions

  1. #1
    Join Date
    Jul 2009
    Posts
    42
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default QMdiSubWindow Questions

    Hello all,

    I am now working on a multi-widget MDI application and am trying to implement my own Subwindow, since i need it to have different behaviours depending on the widget that is set into it.

    My problem is following, i have two widget types where i don't want the subwindow to have a title-bar, but i still want to be able to move and re-size it.
    The only way i have found to remove the title-bar is to apply the Qt::FramlessWindowHint wich also removes the frame and so i lose the ability to re-size the window directly.

    So i would like to write a re-size and Move event that handles the mouse click, move and release events from the widget.

    I have successfully reimplemented these events directly on the widget, but i would rather have this handled directly by the subwindow.

    I hope "you" can make sense of my rambling

    Oh the widgets i am talking about are based on QFrame.

    Thanks for reading, and i hope you can help.

    Eric

  2. #2
    Join Date
    Mar 2007
    Posts
    57
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QMdiSubWindow Questions

    You could sublcass QMdiSubWindow and implement the moveevent/resizeevent handlers there I guess.

    However, probably someone will turn up in this thread with a better solution

  3. #3
    Join Date
    Jul 2009
    Posts
    42
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QMdiSubWindow Questions

    The problem is how do I generate a move/resize Event in my subwindow from my widget or without the frame?

    I have the following code in one of my Widgets. Right now it handles the moving of the widget with its parent and seting the proper resize cursors when hovering the edges.
    But Idealy i would like to ignore the event here and handle it in the subwindow...
    Im not sure if I can do that. I will try to give that a try tomorrow

    Qt Code:
    1. void DisplayComponent::mousePressEvent(QMouseEvent *me)
    2. {
    3. me->accept(); // do not propagate
    4.  
    5. if(me->buttons() == Qt::LeftButton)
    6. {
    7. if(canResize){
    8.  
    9. return QWidget::resizeEvent(dynamic_cast<QResizeEvent*> (me));
    10. }
    11. isMoving = true;
    12. if (parentWidget()->isWindow())
    13. offset = me->globalPos() - pos();
    14. else
    15. offset = me->pos();
    16. }
    17. }
    18.  
    19. void DisplayComponent::mouseReleaseEvent(QMouseEvent *me)
    20. {
    21.  
    22. me->accept(); // do not propagate
    23.  
    24. if(isMoving)
    25. {
    26. offset = QPoint();
    27. isMoving = false;
    28. }
    29.  
    30. }
    31.  
    32. void DisplayComponent::mouseMoveEvent(QMouseEvent *me)
    33. {
    34. me->accept(); // do not propagate
    35.  
    36. if (isMoving)
    37. {
    38. if (parentWidget()->isWindow())
    39. parentWidget()->move(me->globalPos() - offset);
    40. else
    41. parentWidget()->move(parentWidget()->mapToParent(me->pos() - offset));
    42. return;
    43. }
    44.  
    45. canResize = false;
    46. setCursor(Qt::ArrowCursor);
    47. int mouseX = me->pos().x();
    48. int mouseY = me->pos().y();
    49. int frameTopLeft = frameWidth();
    50. int frameBottom = rect().bottom() - frameWidth();
    51. int frameRight = rect().right() - frameWidth();
    52.  
    53. if (mouseX < frameTopLeft)
    54. {
    55. canResize = true;
    56. if (mouseY < frameTopLeft)
    57. {
    58. //isTopLeft();
    59. setCursor(Qt::SizeFDiagCursor);
    60. return;
    61. }
    62. if (mouseY > frameBottom)
    63. {
    64. //isBottomLeft();
    65. setCursor(Qt::SizeBDiagCursor);
    66. return;
    67. }
    68. //isLeft();
    69. setCursor(Qt::SizeHorCursor);
    70. return;
    71. }
    72. if (mouseX > frameRight)
    73. {
    74. canResize = true;
    75. if (mouseY < frameTopLeft)
    76. {
    77. //isTopRight;
    78. setCursor(Qt::SizeBDiagCursor);
    79. return;
    80. }
    81. if (mouseY > frameBottom)
    82. {
    83. //isBottomRight;
    84. setCursor(Qt::SizeFDiagCursor);
    85. return;
    86. }
    87. //isRight;
    88. setCursor(Qt::SizeHorCursor);
    89. return;
    90. }
    91. if(mouseY < frameTopLeft)
    92. {
    93. //isTop;
    94. canResize = true;
    95. setCursor(Qt::SizeVerCursor);
    96. return;
    97. }
    98. if(mouseY > frameBottom)
    99. {
    100. //isBottom;
    101. canResize = true;
    102. setCursor(Qt::SizeVerCursor);
    103. return;
    104. }
    105. //isNormal;
    106. canResize = false;
    107. setCursor(Qt::ArrowCursor);
    108. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by ericV; 1st October 2009 at 15:57.

Similar Threads

  1. QMdiSubWindow Restore Geometry
    By ChrisW67 in forum Newbie
    Replies: 1
    Last Post: 26th June 2009, 08:42
  2. Catching escape event with QMdiSubWindow
    By y.shan in forum Qt Programming
    Replies: 0
    Last Post: 3rd September 2008, 14:02
  3. Close a QMdiSubwindow
    By John_P in forum Qt Programming
    Replies: 4
    Last Post: 14th March 2008, 18:23
  4. Memory management questions (im new to Qt)
    By scarvenger in forum Qt Programming
    Replies: 2
    Last Post: 6th May 2007, 08:41
  5. Qt related questions and thoughts about getting job
    By AlexKiriukha in forum General Discussion
    Replies: 4
    Last Post: 26th January 2006, 13:25

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.