Hi,<div><br></div><div>I<span style="font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif;font-size:14px;line-height:18px;background-color:rgb(255,255,255)"> 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.</span></div>
<div><span style="font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif;font-size:14px;line-height:18px;background-color:rgb(255,255,255)"><br></span></div><div><span style="font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif;font-size:14px;line-height:18px;background-color:rgb(255,255,255)">Should I be setting flags for this column? so far I have something like:</span><br>
<div><br></div><div><pre style="margin-top:0px;margin-bottom:10px;padding:5px;border:0px;font-size:14px;vertical-align:baseline;background-color:rgb(238,238,238);font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif;overflow:auto;width:auto;max-height:600px;line-height:18px">
<code style="margin:0px;padding:0px;border:0px;font-size:14px;vertical-align:baseline;font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif"> if index.column() == 14:
flags |= QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsUserCheckable | Qt.ItemIsEnabled
return flags </code></pre></div><div><br></div><div><br></div><div>This is my delegate, but how do I make the button react to clicks?</div><div><br></div><div>Thanks,</div><div>cris</div><div><br></div><div><br></div>
<div><br></div><div><pre style="margin-top:0px;margin-bottom:10px;padding:5px;border:0px;font-size:14px;vertical-align:baseline;background-color:rgb(238,238,238);font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif;overflow:auto;width:auto;max-height:600px;line-height:18px">
<code style="margin:0px;padding:0px;border:0px;font-size:14px;vertical-align:baseline;font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif">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()</code></pre></div></div>