[英]App crash when using QPainter on QPixmap
我正在尝试制作一个将制作点图形的课程。 该类继承自QWidget。 我希望它在将显示在QLabel中的QPixmap上绘制线条和点。
该类的构造函数如下所示:
MyClass::MyClass()
{
calcul_proprietes(); // Function that makes calculation of what to draw.
pix = new QPixmap(760,350);
dessiner_graphique(); // Function that does the drawing.
//Displaying the qpixmap
layout_principal = new QVBoxLayout(this);
label_pix = new QLabel(this);
label_pix->setPixmap(*pix);
layout_principal->addWidget(label_pix);
this->setLayout(layout_principal);
}
和做图的功能的一小部分
void MyClass::dessiner_graphique()
{
// ...
QPainter painter(pix);
QRect contour(x_depart,y_depart,largeur_grille,hauteur_grille);
painter.drawRect(contour);
// ...
}
我不想使用paintEvent函数,因为它一直被调用,并且我的图形只需要绘制一次。 我做错了什么?
您是否在类构造函数之前调用了默认的基类构造函数?
MyClass( QObject *parent )
: QWidget( parent )
{
// Your posted code.
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.