gpt4 book ai didi

c++ - 在 QPixmap 上使用 QPainter 时应用程序崩溃

转载 作者:太空宇宙 更新时间:2023-11-04 13:33:46 25 4
gpt4 key购买 nike

我正在尝试制作一个可以制作点图形的类。该类继承自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.
}

关于c++ - 在 QPixmap 上使用 QPainter 时应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30490879/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com