QPainter::begin: Widget painting can only begin as a result of a paintEvent
QPainter::setPen: Painter not active
QPainter::drawRects: Painter not active
QPainter::begin: Widget painting can only begin as a result of a paintEvent
QPainter::setPen: Painter not active
QPainter::drawRects: Painter not active
为什么会这样?
更新
代码语言:
javascript
复制
// QPainter( this )
// QTextEdit::paintEvent at the begining of custom PaintEvent
// RESULT: "QPainter::begin: Widget painting can only begin as a result of a paintEvent" ...
virtual void paintEvent(QPaintEvent *_event)
QTextEdit::paintEvent( _event );
QPainter pnt( this );
pnt.setPen( QColor( 0, 0, 0, 0xff ));
pnt.drawRect( 0, 0, width()-1, height()-1);
// QPainter ( viewport() )
// QTextEdit::paintEvent at the begining of custom PaintEvent
// RESULT: works.
virtual void paintEvent(QPaintEvent *_event)
QTextEdit::paintEvent( _event );
QPainter pnt( viewport() );
pnt.setPen( QColor( 0, 0, 0, 0xff ));
pnt.drawRect( 0, 0, width()-1, height()-1);
// *** BONUS ***
// QPainter( viewport() ) or QPainter ( this )
// QTextEdit::paintEvent after QPainter() constructor.
// RESULT: Segmentation fault.
virtual void paintEvent(QPaintEvent *_event)
QPainter pnt( viewport() );