样式表取一部分图片

样式表取部分图片对于最大化最小化按钮一般有四种状态:hover、release、enter、pressed,这四种状态一般是在一

样式表取部分图片
对于最大化最小化按钮一般有四种状态:hover、release、enter、pressed,这四种状态一般是在一张图片中,通过样式表如何取对应的图片呢?
如果答案是以下2种就免了:
1、将一张图片分成四张图片,分别用相应状态去对应;
2、用代码方式btn->setIcon(QIcon(pixmap.copy(QRect(state * nWidth, 0, nWidth, nHeight))));

请一定要用样式表完成的方法!!!

[解决办法]
QImage source(":/1.jpg"); for(quint8 i=0;i<3;i++) 

this->image[i] = new QImage(45,21,QImage::Format_RGB888); //定义三张图片每一张都45*21大小 
QPainter painter(image[i]); 
painter.drawImage(0,0,source,45*i,0,45,21); 
painter.end(); 


this->ui->label->setPixmap(QPixmap::fromImage(*image[0])); 
this->ui->label_2->setPixmap(QPixmap::fromImage(*image[1])); 
this->ui->label_3->setPixmap(QPixmap::fromImage(*image[2])); 
 

这样也能切割图片!