[PyQt] QGraphicsView, QTableView and a QComboBox Editor
Aron Bierbaum
aronbierbaum at gmail.com
Mon Jul 27 19:24:45 BST 2009
We are running into a few issues with item views and QGraphicsView. We
have a custom delegate that displays a combo box with valid values.
The issue we are seeing is that this works great when using the basic
QTableView. But as soon as we add the view to a QGraphicsProxyWidget
so that we can place it in a QGraphicsScene, the combo box no longer
appears when editing. Does anyone have any ideas how to work around
this, or do you know if this is a known issue? I have attached a
simple example showing the issue.
Thanks,
Aron
-------------- next part --------------
import sys
from PyQt4 import QtCore, QtGui
class ListModel(QtCore.QAbstractListModel):
def __init__(self, parent = None):
QtCore.QAbstractListModel.__init__(self, parent)
self._values = [True, False, True, False]
def rowCount(self, parentIdx):
return len(self._values)
def flags(self, index):
"""
Returns the item flags for the given \p index.
"""
if not index.isValid():
return QtCore.Qt.ItemIsEnabled
return QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEditable
def data(self, index, role = QtCore.Qt.DisplayRole):
if not index.isValid():
if role == QtCore.Qt.UserRole:
return None
else:
return QtCore.QVariant()
value = self._values[index.row()]
if QtCore.Qt.UserRole == role:
return values
elif role == QtCore.Qt.DisplayRole or role == QtCore.Qt.EditRole:
return QtCore.QVariant(value)
return QtCore.QVariant()
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
list_view1 = QtGui.QListView()
model1 = ListModel()
list_view1.setModel(model1)
list_view1.setWindowTitle("Working")
list_view1.show()
list_view2 = QtGui.QListView()
model2 = ListModel()
list_view2.setModel(model2)
scene = QtGui.QGraphicsScene()
proxy = scene.addWidget(list_view2)
graphics_view = QtGui.QGraphicsView(scene)
graphics_view.setWindowTitle("Not Working")
graphics_view.show()
app.exec_()
More information about the PyQt
mailing list