• 8688阅读
  • 3回复

怎麼在主視窗加入背景圖? [复制链接]

上一主题 下一主题
离线xuanzon
 
只看楼主 倒序阅读 楼主  发表于: 2007-02-01
如題,程式如下:
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)
离线css520
只看该作者 1楼 发表于: 2007-02-01
加上 w->setAutoFillBackground(true); 确保图片包含在*.qrc文件中
//地球人,你们好。。。
离线xuanzon
只看该作者 2楼 发表于: 2007-02-05
謝謝前輩,可以運作了。
离线alina
只看该作者 3楼 发表于: 2007-05-17
我在windows/qt4下运行此程序,总是报错:
main.obj : error LNK2019: 无法解析的外部符号 "int __cdecl qInitResources_styles(void)" (?qInitResources_styles@@YAHXZ),该符号在函数 _main 中被引用
C:\Documents and Settings\Administrator.C053696591D2477\My Documents\Visual Studio 2005\Projects\test\beijingse\Debug\beijingse.exe : fatal error LNK1120: 1 个无法解析的外部命令。
快速回复
限100 字节
 
上一个 下一个