2013-01-13 36 views
-1

我正在開發視頻處理項目。爲了調試,我需要將一些幀的ROI追加到指定寬度的QLabel中。我需要附加子幀的標籤....有任何想法做到這一點?在Qlabel(Qt)中追加圖像

+2

投資回報率?投資回報? –

+0

感興趣的地區 –

回答

0

你可以使用QLayout(horizintal,Vertical e t.c)和QLabel。嘗試根據需要動態創建QLabels,並添加到佈局。有了這個,U可以添加許多圖片,只要你想...希望它有幫助。

#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型號 http://doc.qt.digia.com/qt/stylesheet-reference.html -Stylesheet參考 您可以通過鏈接檢查樣式表來辨別更好

+0

其實我已經創建了一個Qlabel盒子;我需要知道它是否可以支持顯示圖像captled並獲得追加和finnaly向下滾動,如果圖像超過維... –

+0

我編輯了答案,我希望它滿足您的需求 –