PySide Bugzilla Closed for New Bugs

PySide is now a Qt Add-on and uses the Qt Project's JIRA Bug Tracker instead of this Bugzilla instance. This Bugzilla is left for reference purposes.

Bug 1141 - QAbstractItemDelegate.createEditor() creates incorrect editor (text editor instead QSpinBox for integer data)
: QAbstractItemDelegate.createEditor() creates incorrect editor (text editor in...
Status: RESOLVED INVALID
Product: PySide
Classification: Unclassified
Component: QtGui
: 1.1.0
: PC MS Windows XP/Vista/7
: P5 enhancement
Assigned To: Paulo Alcantara
:
:
:
  Show dependency treegraph
 
Reported: 2012-02-11 18:26 EET by Vladimir Rutsky
Modified: 2012-02-26 07:00 EET (History)
10 users (show)

See Also:


Attachments
Complete example. (455 bytes, text/plain)
2012-02-11 18:26 EET, Vladimir Rutsky
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Vladimir Rutsky 2012-02-11 18:26:28 EET
Created attachment 489 [details]
Complete example.

Consider following example:

    # Create Model and View for it.
    model = QtGui.QStandardItemModel(1, 1)
    view = QtGui.QTableView()
    view.setModel(model)

    # Set data at (0, 0) to number 30:
    model.setData(model.index(0, 0), 30)

Now I double click on cell (0, 0) to start editing data.

1. Expected behavior: QSpinBox appears and allows entering only integer value
(according to this [1], also this is how PyQt behaves on same example).

2. Observed behavior: text editor box appears and you can enter any text
inside.


[1] http://www.pyside.org/docs/pyside/PySide/QtGui/QItemEditorFactory.html
Comment 1 Vladimir Rutsky 2012-02-13 15:36:06 EET
I think I know why text editor appears instead QSpinBox: in attached file there
are strings that checks that data is correctly stored:

    # Set data at (0, 0) to number 30:
    model.setData(model.index(0, 0), 30)

    # Check that data type is numerical, not string
    data = model.data(model.index(0, 0), QtCore.Qt.EditRole)
    print type(data), data  # "<type 'long'> 30" - data stored correctly(?)

Notice that data is stored as 'long' and not as 'int'!

So later, when item is double clicked for modification,
QItemEditorFactory::createEditor is called with 'long' type, instead of 'int',
which leads to creation of generic editor:

>>> print QtGui.QItemEditorFactory.defaultFactory().createEditor('int', None)
<PySide.QtGui.QSpinBox object at 0x034B1E18>
>>> print QtGui.QItemEditorFactory.defaultFactory().createEditor('long', None)
<PySide.QtGui.QWidget object at 0x034B1DC8>

IMO there are two problems:
1. 'int' data stored as 'long' when passing through QVariant (not sure is this
actually a problem),
2. there is no default editor for 'long' type.
Comment 2 Vladimir Rutsky 2012-02-15 12:00:37 EET
Looks like the actual problem was because I used custom build of PySide with Qt
v4.7.2 instead of v4.7.4: this bug doesn't reproduces in official PySide v1.1.0
build.

Please close this bug as invalid.
Comment 3 Paulo Alcantara 2012-02-26 07:00:09 EET
Hi Vladimir,

Marking this bug as INVALID.

Thanks, anyway. :-)


           - Paulo Alcantara