我有一段代码有这行代码:
int dsize = 100;
QPainter *painter;
QPixmap *img;
QLabel *l_img;
painter = new QPainter;
img = new QPixmap(dsize, dsize);
l_img = new QLabel;
l_img->setPixmap(*img);
painter->begin(img);
painter->fillRect(img->rect(), Qt::white);
QPen pen(Qt::black, 12);
painter->setPen(pen);
painter->drawLine(40, 40, 40, 100);
painter->end();
l_img->show();
但是,当我运行代码时,我看不到任何带有黑色矩形的白色图像。事实上,我看到的是用大字体写的窗口标题。似乎没有任何效果,我只是得到这样的图像。我究竟做错了什么?
谢谢!