如題,程式如下:
main.cpp
#include <QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
Q_INIT_RESOURCE(styles);
QApplication app(argc, argv);
MainWindow main;
main.show();
return app.exec();
}
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
class QPushButton;
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow();
protected:
private slots:
private:
};
#endif
mainwindow.cpp
#include <QtGui>
#include <QPixmap>
#include "mainwindow.h"
MainWindow::MainWindow()
{
QWidget *w = new QWidget;
QPalette palette;
QPixmap background(":/images/BtnB13.png");
palette.setBrush(w->backgroundRole(),QBrush(background));
w->setPalette(palette);
setCentralWidget(w);
}
然後執行
make -project
make -makefile
make
./mainwindow
跑出來的視窗卻還是沒有背景圖...
請教各位前輩,我要怎麼改才會有背景圖?謝謝。
(ps.我用的是qt4)