[PyQt] button delegate in a tableview

Erik.Janssens at conceptive.be Erik.Janssens at conceptive.be
Tue Nov 6 22:05:21 GMT 2012


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()


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20121106/6e7b7d16/attachment-0001.html>


More information about the PyQt mailing list