我在Python 2.7中使用PySide 1.2.1,我需要一个小部件来绘制彩色背景.在Qt Designer中,我创建了一个简单的窗口,其中包含一个标签,一个包含三个其他项目和另一个标签的小部件.对于包含按钮的小部件,单选按钮和复选框我将styleSheet属性设置为background-color: #FFFFFF.在Qt Designer中,所有内容都根据需要呈现:

但是在Pyside中,小部件不会绘制背景颜色 - 但是它上面的项目会正确地继承颜色:

这是ui-XML:
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>276</width>
<height>133</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,1,1">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>The following should have white background:</string>
</property>
</widget>
</item>
<item>
<widget class="QWidget" name="widget" native="true">
<property name="styleSheet">
<string notr="true">background-color: #FFFFFF</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>PushButton</string>
</property> …Run Code Online (Sandbox Code Playgroud) 我有一个由具有该函数的unicode字符串构成的十六进制字符串:
def toHex(s):
res = ""
for c in s:
res += "%02X" % ord(c) #at least 2 hex digits, can be more
return res
hex_str = toHex(u"...")
Run Code Online (Sandbox Code Playgroud)
这将返回一个像这样的字符串:
"80547CFB4EBA5DF15B585728"
Run Code Online (Sandbox Code Playgroud)
这是一个由6个中国符号组成的序列.
但
u"Knödel"
Run Code Online (Sandbox Code Playgroud)
转换为
"4B6EF664656C"
Run Code Online (Sandbox Code Playgroud)
我现在需要的是将其转换回原始unicode的功能.中文符号似乎具有2字节表示,而第二个示例具有所有字符的1字节表示.所以我不能只为每个1或2字节块使用unichr().
我已经试过了
binascii.unhexlify(hex_str)
Run Code Online (Sandbox Code Playgroud)
但这似乎逐字节转换并返回一个字符串,而不是unicode.我也试过了
binascii.unhexlify(hex_str).decode(...)
Run Code Online (Sandbox Code Playgroud)
不同的格式.从来没有得到原始的unicode字符串.
非常感谢你提前!