简体   繁体   English

如何编写Qt Creator之类的调整大小小部件的程序(不使用QSizeGrip)

[英]How to program resize widget like Qt Creator (Not using QSizeGrip)

In Qt Creator we can resize widget by moving mouse cursor to blue square point (mouse cursor will change to arrow shape) then we will press left mouse and pull to change size of widget. Qt Creator中,我们可以通过将鼠标光标移到蓝色方形点 (鼠标光标将变为箭头形状)来调整窗口小部件的大小,然后按鼠标左键并拉动以更改窗口小部件的大小。

在此处输入图片说明

I created a widget and i want to implement that resize idea for it. 我创建了一个小部件,我想为其实现该调整大小的想法。 How can i do it ? 我该怎么做 ? Thanks 谢谢

Ok, so there might be some already implemented solution out there, but that how I would go with: 好的,所以可能有一些已经实施的解决方案,但是我将如何处理:

  • Overload those three functions of the parent widget: 重载父小部件的这三个功能:

     void mousePressEvent(QMouseEvent *event); void mouseReleaseEvent(QMouseEvent *event); void mouseMoveEvent(QMouseEvent *event); 
  • Keep track of the initial blue square postition inside the MousePressEvent(...). 跟踪MousePressEvent(...)内的初始蓝色正方形位置。

  • Inside MouseMoveEvent(...) find out the difference between the actual mouse position and the initial one. 在MouseMoveEvent(...)内部,可以发现实际鼠标位置与初始鼠标位置之间的差异。 (Be sure that the user is still clicking ;) ). (确保用户仍在单击;))。

  • Use the previously found delta and resize the widget accordingly. 使用先前找到的增量,并相应地调整小部件的大小。

  • Remember to set a bool or something when the user release the mouse button using the mouseReleaseEvent(...). 当用户使用mouseReleaseEvent(...)释放鼠标按钮时,请记住要设置布尔值或其他内容。

Using those steps, you should have a good prototype running. 使用这些步骤,您应该运行良好的原型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM