子窗口的QStyleSheet(QMainWindows)-添加框架边框

时间:2019-07-12 15:15:36

标签: python pyqt5 qtstylesheets

我正在网上寻找的dark.qss,所以我可以将应用程序设置为黑暗主题。

我将使用QStyleSheet的哪个选项为我的子窗口QMainWindows添加边框?

正如您在深色主题中看到的那样,当两个窗口重叠时,我无法分辨两个窗口的区别。我想在原始图像(蓝色的外边缘)中显示填充/边框

当前:

enter image description here

原文:

enter image description here

链接到Dark.qss dark

MCVE:

Main.py

from TestGUI import Ui_MainWindow
from Calculations import Ui_Calculations
import sys,os,traceback
from PyQt5 import QtCore, QtGui, QtWidgets

class Calculation(QtWidgets.QMainWindow, Ui_Calculations):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.setupUi(self)
        self.actionScreenshot.triggered.connect(self.toggle_stylesheet)

    def toggle_stylesheet(self):
        try:
            app = QtWidgets.QApplication.instance()
            if app is None:
                raise RuntimeError("No Qt Application found.")

            file = QtCore.QFile("C:\\Users\\{0}\\Desktop\\dark.qss".format(os.getlogin())) #input wherever qss file is
            file.open(QtCore.QFile.ReadOnly | QtCore.QFile.Text)
            stream = QtCore.QTextStream(file)
            app.setStyleSheet(stream.readAll())
        except:
            print(traceback.format_exc())
    def toggle_stylesheet_none(self):
        app = QtWidgets.QApplication.instance()
        if app is None:
            raise RuntimeError("No Qt Application found.")
        app.setStyleSheet(None)

class TestGui(QtWidgets.QMainWindow, Ui_MainWindow):
    """Test class"""
    def __init__(self, parent=None):
        super().__init__(parent)
        self.setupUi(self)
        self.CalculationWindow = Calculation()
        self.CreateCalc()

    def CreateCalc(self):
        """create login window """
        try:
            self.subwindow = QtWidgets.QMdiSubWindow()
            self.subwindow.setWidget(self.CalculationWindow)
            self.mdiArea.addSubWindow(self.subwindow)
            self.CalculationWindow.showNormal()
        except:
            print(traceback.format_exc())



def main():
    app = QtWidgets.QApplication(sys.argv)
    app.processEvents()
    TestWindow = TestGui()
    TestWindow.show()
    sys.exit(app.exec_())

if __name__ == '__main__':
    main()

Calculations.py

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'Calculations.ui'
#
# Created by: PyQt5 UI code generator 5.12.2
#
# WARNING! All changes made in this file will be lost!

from PyQt5 import QtCore, QtGui, QtWidgets


class Ui_Calculations(object):
    def setupUi(self, Calculations):
        Calculations.setObjectName("Calculations")
        Calculations.resize(850, 363)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Maximum)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(Calculations.sizePolicy().hasHeightForWidth())
        Calculations.setSizePolicy(sizePolicy)
        Calculations.setMinimumSize(QtCore.QSize(850, 350))
        Calculations.setMaximumSize(QtCore.QSize(860, 363))
        self.centralwidget = QtWidgets.QWidget(Calculations)
        self.centralwidget.setObjectName("centralwidget")
        Calculations.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(Calculations)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 850, 21))
        self.menubar.setObjectName("menubar")
        self.menuScreenshot = QtWidgets.QMenu(self.menubar)
        self.menuScreenshot.setObjectName("menuScreenshot")
        Calculations.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(Calculations)
        self.statusbar.setObjectName("statusbar")
        Calculations.setStatusBar(self.statusbar)
        self.actionScreenshot = QtWidgets.QAction(Calculations)
        self.actionScreenshot.setObjectName("actionScreenshot")
        self.menuScreenshot.addAction(self.actionScreenshot)
        self.menubar.addAction(self.menuScreenshot.menuAction())

        self.retranslateUi(Calculations)
        QtCore.QMetaObject.connectSlotsByName(Calculations)

    def retranslateUi(self, Calculations):
        _translate = QtCore.QCoreApplication.translate
        Calculations.setWindowTitle(_translate("Calculations", "Calculations"))
        self.menuScreenshot.setTitle(_translate("Calculations", "File"))
        self.actionScreenshot.setText(_translate("Calculations", "Screenshot"))

TestGUI.py

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'TestGUI.ui'
#
# Created by: PyQt5 UI code generator 5.12.2
#
# WARNING! All changes made in this file will be lost!

from PyQt5 import QtCore, QtGui, QtWidgets


class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(800, 600)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.gridLayout = QtWidgets.QGridLayout(self.centralwidget)
        self.gridLayout.setObjectName("gridLayout")
        self.mdiArea = QtWidgets.QMdiArea(self.centralwidget)
        self.mdiArea.setObjectName("mdiArea")
        self.gridLayout.addWidget(self.mdiArea, 0, 0, 1, 1)
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 21))
        self.menubar.setObjectName("menubar")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))

0 个答案:

没有答案