2010-09-12 166 views
1

我正在开发基于QScrollArea和QLabel的图像查看器,它包含要显示的图像。在QScrollarea内部绘制QLabel

现在,我需要在标签上显示文本,例如当前鼠标(x,y)位置,图像大小等,但它不受滚动的影响。

我该怎么做?

回答

1

我想尝试的第一件事是:

container = new QWidget(); 
scrollArea = new QScrollArea(container); 
pic = new QLabel(); 
pic->setPixmap(...); 
scrollArea->setWidget(pic); 
infoLabel = new QLabel("mouse is at 0, 0", container); 
infoLabel->move(20, 20); // the desired non-scrolling position 
+0

感谢斯特凡,在您的帮助我拿出我的子类QScrollArea的构造打造“infoLabel”的一个实例,以及所使用的构造infoLabel =新的QLabel(viewPort());然后,在鼠标处理方法中,我只需设置infoLabel-> setText(“some text”);和infoLabel-> adjustSize();使标签适应其内容。 – 2010-09-12 15:49:20