Qt 作为守护进程运行时更改了UI样式
我正在尝试使用Qt创建一个后台应用程序 在前台运行和作为执事运行在ui上是有区别的 自从Ubuntu 11.10以来,样式已经改变Qt 作为守护进程运行时更改了UI样式,qt,daemon,foreground,Qt,Daemon,Foreground,我正在尝试使用Qt创建一个后台应用程序 在前台运行和作为执事运行在ui上是有区别的 自从Ubuntu 11.10以来,样式已经改变 在前台运行应用程序时 当作为守护进程运行时 main.cpp #include <QApplication> #include "form.h" int main(int argc, char* argv[]) { QApplication app(argc, argv);
- 在前台运行应用程序时
- 当作为守护进程运行时
#include <QApplication>
#include "form.h"
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
Form *pForm = new Form();
pForm->show();
return app.exec();
}
form.ui
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>form</class>
<widget class="QWidget" name="form">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>270</x>
<y>240</y>
<width>98</width>
<height>27</height>
</rect>
</property>
<property name="text">
<string>PushButton</string>
</property>
</widget>
<widget class="QTabWidget" name="tabWidget">
<property name="geometry">
<rect>
<x>30</x>
<y>30</y>
<width>341</width>
<height>191</height>
</rect>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
<string>Tab 1</string>
</attribute>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
<string>Tab 2</string>
</attribute>
</widget>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>50</x>
<y>240</y>
<width>141</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string/>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>
形式
0
0
400
300
形式
270
240
98
27
按钮
30
30
341
191
表1
表2
50
240
141
31
这只是一个简单的Ui测试
我认为前台的应用程序将“桌面设置”作为GUI样式应用,但我不知道守护程序应用程序使用哪种样式(上图)
为什么样式不同?为了在任何平台或环境上具有统一的样式,您需要明确设置应用程序样式:
QApplication app(argc, argv);
app.setStyle(new QPlastiqueStyle()); //or similar.
我已经按照你的建议进行了测试,但没有任何变化。我将创建一个单独的应用程序来连接到守护进程。
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>form</class>
<widget class="QWidget" name="form">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>270</x>
<y>240</y>
<width>98</width>
<height>27</height>
</rect>
</property>
<property name="text">
<string>PushButton</string>
</property>
</widget>
<widget class="QTabWidget" name="tabWidget">
<property name="geometry">
<rect>
<x>30</x>
<y>30</y>
<width>341</width>
<height>191</height>
</rect>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
<string>Tab 1</string>
</attribute>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
<string>Tab 2</string>
</attribute>
</widget>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>50</x>
<y>240</y>
<width>141</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string/>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>
QApplication app(argc, argv);
app.setStyle(new QPlastiqueStyle()); //or similar.