我必须将图像显示为屏幕标签。我用标签来显示图像,但标签和标签小部件之间有一些差距。
我正在使用样式表设置图像。
如何消除这个空隙或空间?
app.ui
<?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>800</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label">
<property name="minimumSize">
<size>
<width>0</width>
<height>50</height>
</size>
</property>
<property name="lineWidth">
<number>1</number>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QTabWidget" name="tabWidget">
<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>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
<resources/>
<connections/>
</ui>
main.py
from PySide.QtGui import QApplication, QMainWindow
from PySide.QtUiTools import QUiLoader
import sys
class Main(QMainWindow):
def __init__(self, parent=None):
super(Main, self).__init__(parent)
self.view = QUiLoader().load("app.ui", self)
self.view.label.setStyleSheet("background-image: "
"url(label.png);")
def main():
""" Entry point of application
"""
app = QApplication(sys.argv)
a = Main()
a.view.show()
sys.exit(app.exec_())
if __name__ == "__main__":
main()
答案 0 :(得分:1)
在Qt Designer中,选择垂直布局,然后将layoutSpacing
属性设置为零。
或者,在代码中,您可以这样做:
self.view.verticalLayout.setSpacing(0)