标题:为什么widget的背景不能设置成图片
作者:cph315
日期:2009-06-12 12:44
内容:
各位大侠:
小弟用qte4.5.0,但就是设置不了widget的背景图片。希望高手指点。
代码如下:
#include
#include
#include
#include
#include
#include
int main( int argc, char ** argv )
{
QApplication app(argc, argv);
QWidget *w = new QWidget(0);
w->setAutoFillBackground(true);
QPalette palette2;
palette2.setBrush(QPalette::Window, QBrush(QPixmap("logo.png")));
palette2.setBrush(QPalette::Base, QBrush(QPixmap("logo.png")));
w->setPalette(palette2);
QVBoxLayout *lout = new QVBoxLayout(w);
QTextEdit* edit = new QTextEdit( );
QLabel* label = new QLabel( "This is a transparent label" );
QCheckBox* cb = new QCheckBox( "Check me" );
lout->addWidget(edit);
lout->addWidget(label);
lout->addWidget(cb);
w->show();
QObject::connect( &app, SIGNAL( lastWindowClosed() ),
&app, SLOT( quit() ) );
return app.exec();
}
#1 [shiroki 06-12 17:38]
试了, 在linux下可以。 你用的windows吧? 似乎有点印象好像是windows下用的系统的那套theme, palette不管用。 需要换一个style才行, 不能用vista的style。
#2 [gvim 06-13 19:23]
引用第1楼shiroki于2009-06-12 17:38发表的:
试了, 在linux下可以。 你用的windows吧? 似乎有点印象好像是windows下用的系统的那套theme, palette不管用。 需要换一个style才行, 不能用vista的style。
楼主说他用的是qte-4.5 :)
不过我也试验了embedded的版本,没有问题。 莫非是楼主没有图片文件吧,或者图片被绿坝给过滤了:)
#3 [shiroki 06-14 17:36]
呵呵不好意思, 看得不够仔细。 linux的我试过是可以的。
#4 [haulm 06-16 12:29]
新版本的Qt的确是不行的,还在找解决方案,但不知是不是Qt的BUG。
#5 [haulm 06-16 12:33]
还是绝对路径的问题。