![]() |
qt QListView 4.6.2 editor issues
Hey
I'm trying to write simple pyqt application, however right now all my efforts ends with issues that I can't overcome. It should be really easy application ... At 4.5.3 version of qt I've found wrong checkbox render (there were just simple circle instead of nice checkbox indicator), so I've migrated to 4.6.2. Now checkbox are fine however existing part of code stopped to work :( - all widgets that editor for list entry is build of doesn't work (looks like they don't get any events). No idea if I'm doing something wrong or maybe something has been changed or it is just simple bug. I'm attaching complete test_case - it is just simple list that once you enter into editor state shows push button. I'm unable to make that push button working. I'll appreciate any help. Kasper ______________________________________ import sys from PyQt4 import QtCore, QtGui from PyQt4.QtCore import * from PyQt4.QtGui import * class MyForm(QtGui.QWidget): def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) list_data = ["item1","item2","item3","item4","item5"] lm = MyListModel(list_data,self) self.lv = QListView() self.lv.setModel(lm) # print i self.mdelegate=MyDelegate(self.lv) self.lv.setItemDelegate(self.mdelegate) # layout layout = QVBoxLayout() layout.addWidget(self.lv) self.setLayout(layout) class MyListModel(QAbstractListModel): def __init__(self, datain, parent=None, *args): QAbstractListModel.__init__(self, parent, *args) self.listdata = datain def rowCount(self, parent=QModelIndex()): return len(self.listdata) def data(self, index, role): if index.isValid() and role == Qt.DisplayRole: return QVariant(self.listdata[index.row()]) else: return QVariant() def flags(self, index): return QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsDragEnabled |QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsUserCheckable | Qt.ItemIsEditable class MyDelegate(QStyledItemDelegate): def __init__(self, parent): QStyledItemDelegate.__init__(self, parent) self.editorState=False def createEditor(self, parent, option, index): return MyEditor(parent) class MyEditor(QtGui.QWidget): def __init__(self, parent): QtGui.QWidget.__init__(self, parent) self.button = QtGui.QPushButton("Press me") layout = QVBoxLayout() layout.addWidget(self.button) self.setLayout(layout) QtCore.QObject.connect(self.button, QtCore.SIGNAL("clicked()"), self.echo) def event(self,event): print "event:"+str(event.type()) return QtGui.QWidget.event(self,event) def setValue(self, value): pass def echo(self): print "has been clicked" if __name__ == "__main__": app = QtGui.QApplication(sys.argv) myapp = MyForm() myapp.show() sys.exit(app.exec_()) |
Re: qt QListView 4.6.2 editor issues
According to the official documentation, if you aren't implementing an item factory, you must reimplement the following:
* createEditor() returns the widget used to change data from the model and can be reimplemented to customize editing behavior. * setEditorData() provides the widget with data to manipulate. * updateEditorGeometry() ensures that the editor is displayed correctly with respect to the item view. * setModelData() returns updated data to the model. I see that you only have createEditor reimplemented. The code ran on my desktop, so I'm not sure what else it could be. Anyways, I've made a pastie for anyone else that wants to try and help you so that they don't have to reindent the entire thing like I did. |
Re: qt QListView 4.6.2 editor issues
Thanks for reply
I know about all other methods - I did that (no success), however for test case I've removed them to make it more compact and clear. |
Re: qt QListView 4.6.2 editor issues
why not use style sheets to make you check box look nice?
|
Re: qt QListView 4.6.2 editor issues
OK - here is whole story
with such libs: Code:
[sbox-FREMANTLE_X86: ~] > dpkg -l python2.5-qt4* | grep ii http://www.image-share.com/upload/234/74.png As you can see there is something wrong with checkboxes So I've updated to newest version of qt and pyton-qt Now I've following libs: Code:
[sbox-FREMANTLE_X86: ~] > dpkg -l python2.5-qt4* | grep ii http://www.image-share.com/upload/234/75.png However the same code that was previously working, with new libs doesn't. Once editor has been open - its widgets doesn't work (looks like they doesn't get events). I've no idea what I'm doing wrong and why code that was working now doesn't. Also I've no idea how style sheets may help ? May you know the way to overcome problems with circles instead of checkboxes. Thanks Kasper PS. Screenshots are taken from scratchbox but on real device it looks exactly the same _________________________ test_case.py ________________ Code:
import sys |
Re: qt QListView 4.6.2 editor issues
I played with it a bit, and it actually is firing off events. I think the problem is that it is trying to fit the contents of the layout into the small space within the check box's area instead of occupying the whole thing. I think this because when I double click any of the check boxes, I see a line that I can hover over and highlight. If I click on the line when it's highlighted, echo() is triggered.
Have you tried using an item factory implementation? |
Re: qt QListView 4.6.2 editor issues
Hum :) not yet - but maybe it is worth testing.
Strange thing is that this code was working before ... ... pure chance, I'd say. Anyway I will try and I will post results. |
Re: qt QListView 4.6.2 editor issues
Quote:
by your description and the screenshot that's just what you get. since both radiobutton and checkbox, imo, descend from qpushbutton, you might check your classes/properties. |
Re: qt QListView 4.6.2 editor issues
I can't do what you are saying - checkbox is part of QListView.
Every item within that list can have extra flag for example : QtCore.Qt.ItemIsUserCheckable. That will result in showing extra checkbox every row in list. Implementation of QListView is hiding painting and managing that thing (probably it is not a widget ... but only a "fake" checkbox done with QStyleOptionButton). I've played a bit with that circle checkbox and looks like there were a bug in finding out proper size for checkbox indicator - it is just too small. Looks like that has been fixed in new version. |
All times are GMT. The time now is 04:58. |
vBulletin® Version 3.8.8