سؤال

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?

هل كانت مفيدة؟

المحلول

This is because of layouts. Layouts automatically recalculate when you add/remove or show/hide elements. You can just opt to not use layouts.

نصائح أخرى

You may also want to try setting the opacity to 0.0 instead of hiding the QDoubleSpinBox.

mySpinBox.setWindowOpacity(0.0);

Actually I don't think that will work.

The easiest thing I can think of to do, would be to subclass the QDoubleSpinBox, then override the paint function (and probably the mouse handling) to be turned on and off with your own variable.

A fairly quick but not elegant solution would be to subclass the desired widget, add in an additional bool to make the widget invisible without removing its geometry and a method to toggle it, and in the overloaded paint event, if the bool is true, call the original paint event from the base class, else don't draw anything. This will result in a totally transparent widget that will still accept events, that is why you can also use setEnabled() with the bool to also disable it while it is hidden.

Not very applicable when you want to hide and show many objects, but in the case of one or two it works and is very quick to implement.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top