Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Qt-在应用程序中显示图形_Qt_User Interface_Qt4_Background - Fatal编程技术网

Qt-在应用程序中显示图形

Qt-在应用程序中显示图形,qt,user-interface,qt4,background,Qt,User Interface,Qt4,Background,我有一个运行在Qt中的应用程序,我基本上是在尝试重新换肤。我提供了用于背景、按钮等的图形。项目中没有当前图形。它没有背景,只是使用默认的查找QPushButtons按钮。我正在使用Qt的UI设计编辑器,因为它不允许我在编辑器之外修改mainwindow.UI文件 因此,我能够通过将样式表应用于MainWindow对象来设置应用程序的背景背景图像:url(“/path/to/bg.png”)这很有效。酷。但是现在应用程序中的所有Qlabel都具有完全相同的背景。似乎QWidget的所有成员都继承了

我有一个运行在Qt中的应用程序,我基本上是在尝试重新换肤。我提供了用于背景、按钮等的图形。项目中没有当前图形。它没有背景,只是使用默认的查找QPushButtons按钮。我正在使用Qt的UI设计编辑器,因为它不允许我在编辑器之外修改mainwindow.UI文件

因此,我能够通过将样式表应用于MainWindow对象来设置应用程序的背景<代码>背景图像:url(“/path/to/bg.png”)这很有效。酷。但是现在应用程序中的所有Qlabel都具有完全相同的背景。似乎QWidget的所有成员都继承了其父级的样式表信息。我怎样才能阻止它

我经历的另一件事是,我需要在应用程序的随机位置显示图形。我成功做到这一点的唯一方法是添加另一个QWidget并将样式表设置为该样式表。这是正确的方法吗?显示非交互式图像的最佳方式是什么


谢谢

将样式表添加到QApplication中,并具体说明您想要设置的QWidget样式

以下是您要查找的内容:

#include <QtGui>

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QMainWindow wnd;

    QString style("QMainWindow{ background: red;} QPushButton{ background: blue }");

    app.setStyleSheet(style);

    QPushButton *btn = new QPushButton("Hello", &wnd);

    wnd.show();

    return app.exec();
}
#包括
int main(int argc,char*argv[])
{
QApplication应用程序(argc、argv);
qmainwindowwnd;
QString样式(“QMainWindow{background:red;}QPushButton{background:blue}”);
附录.设置样式表(样式);
QPushButton*btn=新的QPushButton(“你好”、&wnd);
wnd.show();
返回app.exec();
}