日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

QT顯示圖片 共兩大類方法

 cjavahtml 2016-04-27
  QT顯示圖片的方法有很多

  大致為

  label上顯示

  直接畫出來

  1-------------------------label上顯示圖片------------------

  把你的label.png放到工程目錄頂層,直接

  QPixmap pixmap('label.png');

  ui->title_label->setPixmap(pixmap);

  ui->title_label->show();

  ---

  可以直接:

  label->setPixmap(QPixmap('./pic.jpg'));

  或者:

  QImage *image= new QImage('./pic.jpg');

  label->setPixmap(QPixmap::fromImage(image));

  再或者在中途換某個圖像的話:

  QImage *image= new QImage('./pic1.jpg');

  label->setPixmap(QPixmap::fromImage(image));

  ...........

  image->load('./pic2.jpg');


  2----------直接畫出圖片-------------------------

  voidlogindlg::paintEvent(QPaintEvent*)
 {
QPainterpainter(this);
QPixmappix;pix.load('D:/QT/login/login/images/delta.png');
painter.drawPixmap(0,0,100,33,pix);
//painter.drawLine(0,0,100,100);
}




  最后補(bǔ)充-----------程序啟動時的圖片

  QApplication app(argc, argv);

  QSplashScreen *splash = new QSplashScreen;

  splash->setPixmap(QPixmap(':/images/splash.png'));//設(shè)置圖片

  splash->show();//顯示圖片

  Qt::Alignment topRight = Qt::AlignRight | Qt::AlignTop;

  splash->showMessage(QObject::tr('Setting up the main window...'),topRight, Qt::white);//顯示信息

  MainWindow mainWin;

  splash->showMessage(QObject::tr('Loading modules...'),

  topRight, Qt::white); //顯示信息

  loadModules();

  splash->showMessage(QObject::tr('Establishing connections...'),

  topRight, Qt::white); //顯示信息

  establishConnections();

  mainWin.show();

  splash->finish(&mainWin);//圖片一直顯示到mainWin加載完成

  delete splash;//釋放空間,節(jié)省內(nèi)存

  return app.exec();

  來自: http://hi.baidu.com/sdink/blog/item/879e7013027a7fcaa7ef3f83.html

  首先你得加載一張能顯示透明的圖片,jpg格式肯定是不行的,一般都是png

  還有不同的部件加載圖片的方法也不太相同,比如:

  QLabel加載圖片:

  C/C++ code

  QString strPath=imagePath.value(day); //圖片路徑

  QPixmap pix(strPath);

  dayLabel->setPixmap(pix);

  QPushButton加載圖片:

  C/C++ code

  button->setIcon(QIcon('toolbutton.png'));

  button->setIconSize(QSize(48, 48));

  其中setIconSize函數(shù)是用來截取圖片的顯示區(qū)域,如果沒有該函數(shù),該圖片是被縮放的放到圖片上

  用調(diào)色板加載圖片:

  C/C++ code

  QPalette p = palette();

  p.setBrush(QPalette::Button, QBrush(QPixmap('toolbutton.png')));

  setPalette(p);

  另外實(shí)現(xiàn)按鈕的透明:

  C/C++ code

  button->setFlat(true);

  還有就是用繪制事件函數(shù)了:

  C/C++ code

  QPixmap arrayImage('/home/image/array.png'); //圖片路徑

  QRect arrayRect(0,0,50,50); //截取圖片區(qū)域

  QPainter painter;

  painter.drawPixmap(QPoint(100,100),arrayImage,arrayRect); //打印圖片

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多