读书人

如何才能做出这样的Button效果

发布时间: 2012-06-11 17:42:22 作者: rapoo

怎么才能做出这样的Button效果?
像这样:
http://www.flickr.com/photos/79592362@N03/7327922458/in/photostream
我用下面的代码,只能显示方框,Button里面图片显示不出来
LayoutDlg::LayoutDlg(QWidget *parent, Qt::WindowFlags f)
: QDialog(parent,f)
{
setWindowTitle(tr("MyLayout is OK!"));

QPixmap *pixmap = NULL;
pixmap = new QPixmap(200, 150);
pixmap->load(":/images/heart.png");
QIcon *icon = new QIcon(*pixmap);
QPushButton *imageButton = new QPushButton(*icon, "", this);
imageButton->setIconSize(QSize(190, 150));
imageButton->setFixedSize(200, 150);
gridLayout = new QGridLayout(this);
gridLayout->addWidget(imageButton,0,1);
}

[解决办法]
我试了一下,你的代码基本可以把图片显示上来,问题可能出在这句:

C/C++ code
pixmap->load(":/images/heart.png"); 

读书人网 >QT开发

热点推荐