Hi all, 

I've got a QStyledItemDelegate subclass which implements paint() to draw 
the contents of some QTableView cells. How do I make it paint a focus 
rectangle if one of those cells has got focus? I tried this:

class MyDelegate(QStyledItemDelegate):
  ...
    def paint(self, painter, option, index):
      ...
       painter.save()
       if option.state & QStyle.State_HasFocus:
           self.parent().style().drawPrimitive(QStyle.PE_FrameFocusRect, 
option, painter)
      ...
       painter.restore()

but this simply does nothing. No errors, no focus frame. I just want 
the QStyle system to somehow paint the usual focus frame if one of my 
custom painted cells have focus. The QStyle documentation tells me to 
create a QStyleOptionFocusRect and to use initFrom(). But initFrom() 
needs a QWidget which I don't have in this case. 

I just don't get it. 

What's the usual way to get focus frames in QTableView cells painted by custom 
delegates?

Thanks very much for any answer, 

Benno. 
_______________________________________________
PyQt mailing list    [email protected]
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Reply via email to