- C/C++ code
QPainterPath path; path.moveTo(50,50); path.lineTo(100,100); path.lineTo(150,50); path.lineTo(200,100); QPainter painter(this); QPen pen,pen1; pen.setColor(QColor(255,0,0));//红色 painter.setPen(pen); painter.drawPath(path); //下面的代码不加的话,画出来的线就是红色的 pen.setColor(QColor(255,0,255));//紫色 path.moveTo(100,50); path.lineTo(200,200); path.lineTo(300,50); painter.setPen(pen); painter.drawPath(path);//结果画来的的线都是紫色的,为什么呢?