首页 > 解决方案 > 使用 StyleSheet 时 QTabWidget 样式不正确

问题描述

我无法使用 Qt Designer 中的 StyleSheet 正确设置 QTabWidget 的样式。

如何设置标签按钮的样式,它们上的关闭按钮?底部有一个奇怪的白色边框?我怎样才能删除它们?这是它的样式表:

background-color: rgb(58, 68, 102);
border-radius: 4;
border-style: none;

这是一个最小的可重现示例: Python 文件:

from PyQt5.QtWidgets import QApplication, QMainWindow
from PyQt5 import uic

class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        #Loading teh ui file
        uic.loadUi('sir.ui', self)


QApp = QApplication([])

window = MainWindow()
window.show()

QApp.exec()

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>805</width>
    <height>625</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(38, 43, 68);</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QTabWidget" name="tabWidget">
    <property name="geometry">
    <rect>
    <x>10</x>
    <y>0</y>
    <width>781</width>
    <height>581</height>
    </rect>
    </property>
    <property name="focusPolicy">
    <enum>Qt::TabFocus</enum>
    </property>
    <property name="contextMenuPolicy">
    <enum>Qt::DefaultContextMenu</enum>
    </property>
    <property name="acceptDrops">
    <bool>true</bool>
    </property>
    <property name="styleSheet">
    <string notr="true">background-color: rgb(58, 68, 102);
border-radius: 4;
border-style: none;</string>
    </property>
    <property name="tabPosition">
    <enum>QTabWidget::North</enum>
    </property>
    <property name="currentIndex">
    <number>0</number>
    </property>
    <property name="elideMode">
    <enum>Qt::ElideRight</enum>
    </property>
    <property name="tabsClosable">
    <bool>true</bool>
    </property>
    <property name="movable">
    <bool>true</bool>
    </property>
    <widget class="QWidget" name="tab_2">
    <attribute name="title">
    <string>Home</string>
    </attribute>
    </widget>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
    <rect>
    <x>0</x>
    <y>0</y>
    <width>805</width>
    <height>21</height>
    </rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>

这是当前状态:

(图片在这里)

标签: python-3.xpyqt5qt-designerqtstylesheetsqtabwidget

解决方案


推荐阅读