2

I'm trying to hide a QDoubleSpinBox in a Qt interface program, using c++.

I have found the function hide(), but it is not working as I expected, since when I hide the element, the space it used to occupy, is not taken into account, so all my window turns crazy. I was wondering if there is any function to hide and keep the space occupied, like if it is normal. I thought that maybe would be a function like this because is common in other frameworks or even JavaScript.

If there is not... any solution?

4

3 回答 3

3

这是因为布局。当您添加/删除或显示/隐藏元素时,布局会自动重新计算。您可以选择不使用布局。

于 2013-03-01T16:11:24.220 回答
2

您可能还想尝试将不透明度设置为 0.0,而不是隐藏 QDoubleSpinBox。

mySpinBox.setWindowOpacity(0.0);

实际上,我认为这行不通。

我能想到的最简单的事情是继承 QDoubleSpinBox,然后用您自己的变量覆盖要打开和关闭的绘制函数(可能还有鼠标处理)。

于 2013-03-01T16:16:53.390 回答
0

一个相当快速但不优雅的解决方案是对所需的小部件进行子类化,添加一个额外的 bool 以使小部件不可见而不删除其几何形状和切换它的方法,并在重载的绘制事件中,如果 bool 为真,则调用来自基类的原始绘制事件,否则不绘制任何东西。这将导致一个仍然接受事件的完全透明的小部件,这就是为什么您也可以使用setEnabled()bool 来在隐藏时禁用它。

当您想要隐藏和显示许多对象时不太适用,但在一个或两个的情况下它可以工作并且非常快速地实现。

于 2013-03-02T08:58:27.513 回答