该问题出现在QGraphicsItem重写paint或者QWidget重写paintEvent中,对于多边形在外面设置brush,但不起作用。看如下定义便知道原因了:
由定义可知,两种定义的区别:
QBrush brush1;
brush1.setColor(QColor(255,0,0)); 其中Qt::BrushStyle为NoBrush
QBrush brush2(QColor(255, 0, 0));其中Qt::BrushStyle为 SolidPattern
而在QGraphicsItem重写paint或者QWidget重视paintEvent中,this->brush()的Qt::BrushStyle为NoBrush,表示不填充。