PDA

View Full Version : my first qt application, everythings ok, but background image get nothing. help me!!!



mackluo
24th December 2011, 16:03
#include <QtGui>

int main(int argc, char** argv){
QApplication apps(argc, argv);
apps.setApplicationName("Application Demo");

QPalette palette;
palette.setBrush(QPalette::Window, QBrush(QPixmap("demo.jpg")));

QMainWindow wnds;
wnds.setAutoFillBackground(true);
wnds.setWindowTitle("QMainWindow Demo");
wnds.setWindowFlags(wnds.windowFlags() & ~Qt::WindowMinimizeButtonHint & Qt::FramelessWindowHint);
wnds.setPalette(palette);
wnds.statusBar()->showMessage("StatusBar Ready");
wnds.resize(800,600); // pixmap.size()
wnds.show(); // wnds.showMaximized();

return apps.exec();
}

Lykurg
24th December 2011, 16:17
Hi,

what is

QPixmap p;
qWarning() << p.load("demo.jpg");
qWarning() << p.isNull(); telling you? I bet your path is wrong. As a solution use Qt's resource system to embed the image to your application or use a valid path...

Oleg
24th December 2011, 16:26
Your code works, so check path to the image.

mackluo
24th December 2011, 16:56
oh yes! qtWarning return QPixmap::load("demo.jpg") as false.
thanks everybody, this is very helpful. i should use qt's resource next time.