我正在尝试在 QPixmap 中使用 QPainter 进行绘制,将 QPixmap 放在 QLabel 中,并将 QLabel 放在 QScrollArea 中。
有时绘制的像素图比我的 ScrollArea 允许的大,但不知何故它不会滚动以显示其余部分。我究竟做错了什么?
QPixmap *pixmap = new QPixmap(10000,500);
QLabel *labeltime = new QLabel;
QHBoxLayout *layout = new QHBoxLayout;
pixmap->fill(QColor("transparent"));
int currentX = 0;
const int currentY = 220;
const int height = 50; // Coming from some static data initialization
QPainter *painter = new QPainter(pixmap);
QPen pen(Qt::gray, 2);
painter->setPen(pen);
for(int i = 0; i< viewlist.size(); i++)
{
QBrush brush(QColor(viewlist[i].color));
painter->setBrush(brush);
painter->drawRect(currentX, currentY, viewlist[i].length, height);
currentX += viewlist[i].length;
}
labeltime->setPixmap(*pixmap);
layout->addWidget(labeltime);
ui->overview->setLayout(layout);
我知道这是添加像素图的一种漫长而奇怪的方法,但我希望它是可滚动的,而且我不能在 QScrollArea 上绘画。有没有更好的办法?或者有人可以告诉我出了什么问题吗?
谢谢