Congratulations to our 2022 Qt Champions!

Text obscured after I reimplement QDoubleSpinBox::sizeHint() and QDoubleSpinBox::minimumSizeHint()

  • I have come across a class derived from QDoubleSpinBox that in its ctor sets the range to negative max double <-> positive max double. I could change that, but it means I will have to test thousands of instances of this class. The problem is when this class is used in Qt5.4.0, the width component of the sizeHint() of the spinbox is thousands of pixels wide. This is not the case in Qt4. I guess it's because of the setRange to include all possible doubles.

    I reimplemented sizeHint() and minimumSizeHint(), and that works great, EXCEPT that now, when the user spins the box or types in values, the resulting value disappears. It will reappear if you use left/right arrow or click with the mouse.

    Is there a non-invasive solution to this secondary problem?

  • Ha! I figured out the problem. This effort is all part of a port from Qt4 to Qt5, and there are other issues beside the one I was addressing. What I was seeing must be some issue with style (I had already noticed I wasn't getting the style I expected) and the text was being rendered white on a white background when the underlying QLineEdit's selectAll() slot was called.

    So, my reimplementation of sizeHint() and minimumSizeHint() are fine, and had nothing to do with the effect I was seeing (I was able to replicate it without my fix). My fix in Qt4 works fine, but of course isn't necessary there.

Log in to reply