Re: [PyQt] can't create a QPainter in QTreeWidget's paintEvent
Here is a dummy version of a derived tree widget: class MyTreeWidget(QTreeWidget): def __init__(self, parent=None): QTreeWidget.__init__(self, parent) def paintEvent(self, e): QTreeWidget.paintEvent(self, e) painter = QPainter(self) painter.end() When an instance is added to a layout, I get the following: QPainter::begin: Widget painting can only begin as a result of a paintEvent QPainter::end: Painter not active, aborted Any ideas what is causing the the painter to think it's not actually in a paintEvent? I'm using Qt 4.3.1, PyQt 4.3 and SIP 4.7 The first thing to look at is whether e is a paint event or not: Yes, it is a paint event. I'm also not calling paintEvent() explicitly anywhere - it's just being triggered off the main loop. ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] can't create a QPainter in QTreeWidget's paintEvent
On Wed Aug 22 21:49:05 BST 2007, Devon wrote: Here is a dummy version of a derived tree widget: [...] def paintEvent(self, e): QTreeWidget.paintEvent(self, e) painter = QPainter(self) painter.end() [...] When an instance is added to a layout, I get the following: QPainter::begin: Widget painting can only begin as a result of a paintEvent QPainter::end: Painter not active, aborted Any ideas what is causing the the painter to think it's not actually in a paintEvent? If you pass a device (self in this case) when you create a QPainter, don't call its begin() or end() methods. I think its the end() call that actually triggers this message in this case. David ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] can't create a QPainter in QTreeWidget's paintEvent
If you pass a device (self in this case) when you create a QPainter, don't call its begin() or end() methods. I think its the end() call that actually triggers this message in this case. I'm not explicitly calling begin() - I believe that's happening in QPainter(self). painter.end() is not the root cause. this script produces the issue if anyone wants to try it: - import sys from PyQt4.QtCore import * from PyQt4.QtGui import * class MyTreeWidget(QTreeWidget): def __init__(self, parent=None): QTreeWidget.__init__(self, parent) def paintEvent(self, e): QTreeWidget.paintEvent(self, e) painter = QPainter(self) if __name__ == __main__: app = QApplication(sys.argv) tree = MyTreeWidget() tree.show() sys.exit(app.exec_()) - Outputs: QPainter::begin: Widget painting can only begin as a result of a paintEvent ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] can't create a QPainter in QTreeWidget's paintEvent
On Thu Aug 23 16:04:19 BST 2007, Devon wrote: If you pass a device (self in this case) when you create a QPainter, don't call its begin() or end() methods. I think its the end() call that actually triggers this message in this case. I'm not explicitly calling begin() - I believe that's happening in QPainter(self). painter.end() is not the root cause. OK. I just noticed the use of an explicit end() without an explicit begin() and jumped to conclusions about the cause of the problem. Sorry about that. Anyway, it looks like we're trying to paint onto the wrong device - the QAbstractScrollArea documentation for its paintEvent() method says this: This event handler can be reimplemented in a subclass to receive paint events (passed in event), for the viewport() widget. Note: If you open a painter, make sure to open it on the viewport(). So you write your paintEvent() to do this instead: def paintEvent(self, e): QTreeWidget.paintEvent(self, e) painter = QPainter(self.viewport()) David ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] can't create a QPainter in QTreeWidget's paintEvent
On 8/23/07, David Boddie [EMAIL PROTECTED] wrote: On Thu Aug 23 16:04:19 BST 2007, Devon wrote: If you pass a device (self in this case) when you create a QPainter, don't call its begin() or end() methods. I think its the end() call that actually triggers this message in this case. I'm not explicitly calling begin() - I believe that's happening in QPainter(self). painter.end() is not the root cause. OK. I just noticed the use of an explicit end() without an explicit begin() and jumped to conclusions about the cause of the problem. Sorry about that. Anyway, it looks like we're trying to paint onto the wrong device - the QAbstractScrollArea documentation for its paintEvent() method says this: This event handler can be reimplemented in a subclass to receive paint events (passed in event), for the viewport() widget. Note: If you open a painter, make sure to open it on the viewport(). So you write your paintEvent() to do this instead: def paintEvent(self, e): QTreeWidget.paintEvent(self, e) painter = QPainter(self.viewport()) David Perfect. Thanks for your help! ~ Devon ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[PyQt] can't create a QPainter in QTreeWidget's paintEvent
Hi, folks - Here is a dummy version of a derived tree widget: class MyTreeWidget(QTreeWidget): def __init__(self, parent=None): QTreeWidget.__init__(self, parent) def paintEvent(self, e): QTreeWidget.paintEvent(self, e) painter = QPainter(self) painter.end() When an instance is added to a layout, I get the following: QPainter::begin: Widget painting can only begin as a result of a paintEvent QPainter::end: Painter not active, aborted Any ideas what is causing the the painter to think it's not actually in a paintEvent? I'm using Qt 4.3.1, PyQt 4.3 and SIP 4.7 Thanks ~ Devon ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] can't create a QPainter in QTreeWidget's paintEvent
On Wednesday 22 August 2007 13:49, Devon wrote: Hi, folks - Here is a dummy version of a derived tree widget: class MyTreeWidget(QTreeWidget): def __init__(self, parent=None): QTreeWidget.__init__(self, parent) def paintEvent(self, e): QTreeWidget.paintEvent(self, e) painter = QPainter(self) painter.end() When an instance is added to a layout, I get the following: QPainter::begin: Widget painting can only begin as a result of a paintEvent QPainter::end: Painter not active, aborted Any ideas what is causing the the painter to think it's not actually in a paintEvent? I'm using Qt 4.3.1, PyQt 4.3 and SIP 4.7 The first thing to look at is whether e is a paint event or not: if e.type () == QEvent.Paint: print Paint Event else: print not Paint Event, e.type () The values for e.type () are on the QEvent page in the Qt docs. Jim ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt