Qt QPixmap QPainter问题
我有一段代码,其中包含以下代码行:
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();
然而,当我运行代码时,我没有看到任何带有黑色矩形的白色图像。事实上我看到的是用大字体写的窗口标题。似乎没什么用,我只是得到了这样的图像。我做错了什么?
谢谢你!
I have a piece of code that has this lines of code:
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();
How ever when I run the code, I don't see any white image with a black rectangle on it. In fact what I see is the title of the window written in big fonts. Nothing seems to work, I just get an image like that. What am I doing wrong?
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
知道了!!
它有这样一行:
应该在
谢谢你之后,xD。
Got it!!
It has this line:
It should be after
Thank you, xD.