[PyQt] button delegate in a tableview

Cristobal Infante cgcris at gmail.com
Wed Jan 30 10:32:05 GMT 2013


Hi,

Sorry to bump this thread again.

I am almost done with my PYQT application but I  still have this glitch on
my button delegate..

Are there any alternatives to using buttons delegate in tableviews?

But I need a button per row...

Best,
Cris

On 8 November 2012 21:53, Cristobal Infante <cgcris at gmail.com> wrote:

> Hi Erik,
>
> Thanks again for your reply, It's good to know that at least I am making
> some progress
> with PyQt and have arrived to a dead end ;)
>
> To be honest I am fine with it, will just have to explain my users they
> will have to
> activate the cell before clicking.
>
> The important thing was to have my button clicking and that has been
> achieved.
>
> Thanks!
> Cris
>
>
> On 8 November 2012 17:09, Erik Janssens <Erik.Janssens at conceptive.be>wrote:
>
>> **
>>
>> Hi Chris,
>>
>>
>>
>> I'm not sure if this can be fixed, maybe you can ask this
>>
>> on the Qt info mailing list. If it can be fixed, I'm interested
>>
>> in the solution ;)
>>
>>
>>
>> What happens is, when the TableWidget receives a click, it
>>
>> creates an editor, but the editor has not yet received the
>>
>> click. That is perfect in most cases, but in case you draw
>>
>> a button it isn't.
>>
>>
>>
>> Cheers,
>>
>>
>>
>> Erik
>>
>>
>>
>>
>>
>> On Wednesday, November 07, 2012 02:50:17 PM Cristobal Infante wrote:
>>
>> 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.Janssens at 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 at riverbankcomputing.com
>> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>>
>>
>>
>>
>>
>> _______________________________________________
>> PyQt mailing list    PyQt at riverbankcomputing.com
>> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20130130/c4cf0bbc/attachment.html>


More information about the PyQt mailing list