我正在做一个视频处理项目。为了调试,我需要将一些帧的 ROI 附加到指定宽度的 QLabel 中。我需要将子帧附加到标签....有什么想法吗?
问问题
875 次
1 回答
0
您可以使用 QLayout(horizintal, Vertical e tc) 和 QLabel。尝试根据需要动态创建 QLabels,并添加到布局中。有了这个,你可以添加尽可能多的图片......希望它有所帮助。
#include <QtGui/QApplication>
#include <QLabel>
#include <QImage>
#include <QLayout>
#include <QMainWindow>
#include <QStringList>
#include <QDebug>
#include <QScrollArea>
//This assumes that the pictures are in the application's Current working directory
//Four pictures used with names 1.png,2.png,3.png and 4.png respectively
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QMainWindow w;
QWidget *central = new QWidget(&w);
w.setCentralWidget(central);
QLayout *test_layout = new QVBoxLayout(central);
QStringList file_names;
file_names <<"1"<<"2"<<"3"<<"4";
foreach(QString pics, file_names){
QLabel* imagethings = new QLabel();
QImage image(QString("%1.png").arg(pics));//QImage's Constructor takes a file path
imagethings->setPixmap(QPixmap::fromImage(image));
test_layout->addWidget(imagethings);//append the new image
}
// remove Space as a result of widget Margin(see link for Box Model below)
central->setStyleSheet("QLabel{border:0px; margin:0px; padding:0px;}");
central->layout()->setContentsMargins(0,0,0,0);//remove Spac as a result of Layout Margins
//Please try to take advantage of Qt's Detailed Documentatio that Comes with the SDK
w.show();
return a.exec();
}
http://doc.qt.digia.com/qt/stylesheet-customizing.html -Box Model http://doc.qt.digia.com/qt/stylesheet-reference.html -Stylesheet Reference 您可以通过链接查看让样式表更好地辨别
于 2013-01-14T23:51:05.197 回答