• 3138阅读
  • 0回复

[提问]Qt5.3自带例子queuedcustomtype的一点疑问 [复制链接]

上一主题 下一主题
离线weiweiqiao
 

只看楼主 倒序阅读 楼主  发表于: 2014-09-10
这个例子是加载图片后,在QLabel控件中逐渐显示出完整图片的程序。
我的疑惑是为什么在Window的loadImage和addBlock方法中都要有label->setPixmap?我在loadImage时已经将图片加载到label控件中,为什么还要在addBlock中再次加载???
  1. void Window::loadImage(const QImage &image)
  2. {
  3.     QDesktopWidget desktop;
  4.     QImage useImage;
  5.     QRect space = desktop.availableGeometry();
  6.     if ((image.width() > 0.75 * space.width())
  7.             || (image.height() > 0.75*space.height())) {
  8.         useImage = image.scaled(0.75*space.width(), 0.75*space.height(),
  9.                                 Qt::KeepAspectRatio, Qt::SmoothTransformation);
  10.     } else {
  11.         useImage = image;
  12.     }
  13.     pixmap = QPixmap(useImage.width(), useImage.height());
  14.     pixmap.fill(qRgb(255, 255, 255));
  15.     label->setPixmap(pixmap);
  16.     loadButton->setEnabled(false);
  17.     resetButton->setEnabled(true);
  18.     thread->processImage(useImage);
  19. }
17行。

  1. void Window::addBlock(const Block& block)
  2. {
  3.     //get color from block and set the alpha parameter of color.
  4.     QColor color = block.color();
  5.     color.setAlpha(64);
  6.     QPainter painter;
  7.     painter.begin(&pixmap);
  8.     painter.fillRect(block.rect(), color);
  9.     painter.end();
  10.     const QPixmap* p1 = label->pixmap();
  11.     QPixmap* p2 = &pixmap;
  12.     //add pixmap to label widget and to show.
  13.     label->setPixmap(pixmap);
  14. }
14行。


Jobs Insanely Great.
快速回复
限100 字节
 
上一个 下一个