天天看点

QLabel 图片大小设定

 QLabel 图片大小设定

QVariant var= index.model()->data(index,Qt::DisplayRole);  
QString strStempJpgPath = var.toString();  
QPixmap pixmap(strStempJpgPath);  
//int width=pixmap.width();  
//int height=pixmap.height();  
  
/* For example, if you have code like 
pixmap.resize(size); 
you can rewrite it as 
pixmap = pixmap.copy(QRect(QPoint(0, 0), size)); 
*/  
  
//pixmap = pixmap.copy(QRect(QPoint(10, 10), size)); //图片去掉边缘  
  
//将图片的宽和高都缩放,并且在给定的矩形内保持宽高的比值  
pixmap = pixmap.scaled(option.rect.width(),option.rect.height(),Qt::KeepAspectRatio);  
painter->drawPixmap(option.rect.x(),option.rect.y(),pixmap);  
break;