查看完整版本: [-- QT背景图片(已解决) --]

QTCN开发网 -> Qt基础编程 -> QT背景图片(已解决) [打印本页] 登录 -> 注册 -> 回复主题 -> 发表主题

faholiang 2010-01-26 19:08

QT背景图片(已解决)

我是一个QT新手
我在自己电脑上做了一个QT界面,所用工具为QTCreator,我给窗口Widget设置背景图片,在我本机是成功的,
可为什么我把该程序拷到其他机器上上无法显示背景呢?
如果是填充颜色是没有问题的

填充图片源代码:
    centralWidget = new QWidget(this);
    centralWidget->setObjectName(QString::fromUtf8("centralWidget"));
    QPalette palette1=this->palette();
    palette1.setBrush(QPalette::Window,QBrush(QPixmap("image/bg.jpg")));
    centralWidget->setPalette(palette1);
    centralWidget->setAutoFillBackground(true);

希望各位QT大侠们帮忙,在下谢了

yangfanxing 2010-01-26 19:12
可能就是路径的错误了;

("image/bg.jpg")该文件是否与*.exe同目录?或许是("./image/bg.jpg")));

较好的方法是添加资源。。。

faholiang 2010-01-26 19:14
路径应该没问题的,因为我在机机测试过了

yangfanxing 2010-01-26 19:23
看看目录,图像文件和执行文件的结构,或许在两台机器上不一样~~~
呵呵。。。我就是说说。。。

午小夜 2010-01-26 19:43
個人比較喜歡用qt stylesheet去設置。
this->setStyleSheet("background-image:url(./image/bg.png);");

benbenmajia 2010-01-27 09:06
我看也像是路径有问题,不会资源没一起吧?

dbzhang800 2010-01-27 09:18
图片插件没随程序发布

faholiang 2010-01-27 10:37
关于dbzhang800 ,我觉得您说的有点道理,不过我不知道QT图片插件指的是?
因为我还是新手

午小夜 2010-01-27 10:43
要顯示jpg圖片,必須帶上支持jpg格式圖片的插件.在 $QTSDK/qt/plugins/imageformats/  目錄下。。。

qt程序中默認只支持png。

faholiang 2010-01-27 11:01
郁闷,我也把qjpegd4.dll文件拷到exe目录下了。为什么还是不显示
我的exe跟图片的关系是exe同目录有一个image文件夹,里面有张bg.jpg
我觉得用午小夜兄的stylesheet 路径地址用 ./image/bg.jpg 应该是没有问题的。
不过我这边还是没有显示,请大家们帮我看看还有什么端倪

午小夜 2010-01-27 11:28
have a look at  Deploying an Application on Windows.
Qt Plugins

Your application may also depend on one or more Qt plugins, such as the JPEG image format plugin or a SQL driver plugin. Be sure to distribute any Qt plugins that you need with your application, and note that each type of plugin should be located within a specific subdirectory (such as imageformats or sqldrivers) within your distribution directory, as described below.

Note: If you are deploying an application that uses QtWebKit to display HTML pages from the World Wide Web, you should include all text codec plugins to support as many HTML encodings possible.

The search path for Qt plugins is hard-coded into the QtCore library. By default, the plugins subdirectory of the Qt installation is the first plugin search path. However, pre-determined paths like the default one have certain disadvantages. For example, they may not exist on the target machine. For that reason, you need to examine various alternatives to make sure that the Qt plugins are found:

.Using qt.conf. This approach is the recommended if you have executables in different places sharing the same plugins.
.Using QApplication::addLibraryPath() or QApplication::setLibraryPaths(). This approach is recommended if you only have one executable that will use the plugin.
.Using a third party installation utility to change the hard-coded paths in the QtCore library.

If you add a custom path using QApplication::addLibraryPath it could look like this:

qApp->addLibraryPath("C:/customPath/plugins");
......

faholiang 2010-01-27 13:37
问题已经解决,
原来插件原本有一个imageformats目录,我拷了里面的dll,但没设目录,还是没显示出来
于是我在exe同目录下就建了一个imageformats的文件夹,把相关dll放到该文件夹,于是图片出现了。
眼睛刷一亮,太高兴了。
真的是谢谢各位的热心帮助
不过还有一点。这个建用插件应该是可以自己设路径的吧?
lib+=qjpegd4.dll?

baskerle 2010-03-13 12:03
问下怎么让图片大小跟窗口一样大啊???

yangfanxing 2010-03-13 14:22
引用第12楼baskerle于2010-03-13 12:03发表的  :
问下怎么让图片大小跟窗口一样大啊???

图片scale为窗口的size

benbenmajia 2010-03-16 11:51
如果拷贝出来了可以用相对路径

benbenmajia 2010-03-16 11:51
这些跑进来发广告的都是些变态


查看完整版本: [-- QT背景图片(已解决) --] [-- top --]



Powered by phpwind v8.7 Code ©2003-2011 phpwind
Gzip disabled