Hi Eric, Thanks for the tip, I've managed to get my button inside my tableview.
There is only one thing that bothers me, not sure if it is a limitation or something I can fix. To be able to press a button, I need to "activate" the containing cell with a click. Once the cell is active I can press the button. This could become confusing for your average user. Is this fixable? Best, Cris On 6 November 2012 22:05, <erik.janss...@conceptive.be> wrote: > ** > > The delegate itself can only paint, it cannot react to > > clicks, you should implement the createEditor method, > > the editor then reacts to clicks > > > > On Tuesday, November 06, 2012 09:59:03 PM Cristobal Infante wrote: > > Hi, > > > I am trying to embed a button per row inside a tableview. My botton are > drawing correctly as delegates but are not reacting to any clicks. > > > Should I be setting flags for this column? so far I have something like: > > > if index.column() == 14: > > flags |= QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsUserCheckable > | Qt.ItemIsEnabled > > return flags > > > > This is my delegate, but how do I make the button react to clicks? > > > Thanks, > > cris > > > > > class AButton(QtGui.QStyledItemDelegate): > > mouse_isPressed = False > > > def __init__(self, parent = None): > > QtGui.QStyledItemDelegate.__init__(self, parent) > > > def boundingRect(self): > > return QtCore.QRectF(0, 0, 40, 40) > > > def paint(self, painter, option, widget = 0): > > opt = QtGui.QStyleOptionButton() > > > opt.state = ((QtGui.QStyle.State_Sunken if self.mouse_isPressed else > QtGui.QStyle.State_Raised) | QtGui.QStyle.State_Enabled) > > opt.text = self.text() > > opt.icon = self.icon() > > opt.rect = option.rect > > opt.palette = option.palette > > QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_PushButton, opt, > painter) > > > def text(self): > > return QtCore.QString("hi") > > > def icon(self): > > return QtGui.QIcon() > > > def mousePressEvent(self, event): > > self.mouse_isPressed = True > > print "HELLO" > > self.update() > > > def mouseReleaseEvent(self, event): > > self.mouse_isPressed = False > > self.update() > > > > > _______________________________________________ > PyQt mailing list PyQt@riverbankcomputing.com > http://www.riverbankcomputing.com/mailman/listinfo/pyqt >
_______________________________________________ PyQt mailing list PyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt