[Qt-interest] QDoubleSpinBox can't undo change after losing focus, is this a bug?

Constantin Makshin cmakshin at gmail.com
Tue Aug 23 16:08:22 CEST 2011


I agree this QDoubleSpinBox's behavior is counter-intuitive, but I said it's not a bug because QDoubleSpinBox doesn't have its own undo buffer and QLineEdit's one works as it was designed to work. And I'm not sure it's going to be easy to fix that — QLineEdit doesn't provide any API to disable its undo buffer, so if one just adds one to the QDoubleSpinBox itself:
1) in the "best" case, QDoubleSpinBox's undo buffer simply wouldn't work due to the QLineEdit capturing all related context menu and keyboard events;
2) in the worst case, these two undo buffers might conflict with each other (e.g. edit the text directly and QLineEdit'll store that in its undo buffer, then change the spin box' value with up/down key/arrow and that'll go to the spin box' undo buffer), leading to even more confusing behavior/bugs.

On Monday, August 22, 2011 09:54:41 AM Andre Somers wrote:
> Op 20-8-2011 14:06, Constantin Makshin schreef:
> > No, this is not a bug --- if the entered value doesn't contain all required components (not enough digits before/after the decimal separator or lack of the separator itself), QDoubleSpinBox calls the setText() function of its edit field to "fix" the value, clearing this field's undo buffer.
> >
> > As a proof you may try this (by default, QDoubleSpinBox expects two digits after the decimal separator):
> > 1) focus ? enter an integer number or a floating point number with 1 digit in the fractional part ? "unfocus" --- the spin box changes its contents and you won't be able to undo your changes;
> > 2) focus ? enter a floating point number with 2 digits in the fractional part ? "unfocus" --- format of the entered value is correct, the spin box stays intact and you can undo your changes.
> Your explanation on how the issue arises is quite clear, thank you. But 
> how does that disqualify it as a bug?
> 
> A QDoubleSpinBox is, from the programmers and users point of view, one 
> single element that you can interact with. Nobody cares that internally 
> it uses a QLineEdit and that QLineEdit resets its undo buffer as soon as 
> you call setText on it. The programmer did not call setText on the 
> QDoubleSpinBox, and thus he expects the the undo feature to Just 
> Work(TM). IMHO, the problem is that the undo buffer of the QLineEdit is 
> used at all. QDoubleSpinBox needs its own undo buffer that _does_ allow 
> the user to undo and redo properly, no matter what kind of formatting 
> fixes were applied to the number entered in the line edit part of the 
> spin box.
> 
> André
> 
> 
> > On Saturday, August 20, 2011 06:39:44 AM liang jian wrote:
> >>      To produce this problem, open Qt Designer, create a widget and
> >> drag a spin box and a double spin box to this widget. Press Ctrl+R to
> >> preview it, change the text in the spin box to a different value and
> >> then click the double spin box, change its value too, return to the
> >> spin box and right click to show the context menu, you will see undo
> >> menu item is enabled, but if you go back to the double spin box and
> >> right click to show the context menu you will see that the undo menu
> >> item is grayed (I think at that time it should be enabled).  I can
> >> produce this problem in both my windows 7 and ubuntu 11.04 system, is
> >> this a bug or a feature?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110823/01b5146b/attachment.bin 


More information about the Qt-interest-old mailing list