如何使用 pyside2 编辑按钮的样式?

How can I edit the style of button with pyside2?

现在我用Pyside2做了一个UI,但是按钮的样式很老,跟winxp的一样。想更新,不知道怎么弄,有大佬知道怎么弄吗?

现在ui

我想要的

我的代码就是这样:

class MainWindow(QMainWindow):

    def __init__(self, parent=None):
        QMainWindow.__init__(self, parent)
        self.open_directory_button = QPushButton("打开文件夹")
self.open_directory_button.clicked.connect(self.open_directory_button_clicked)
        self.path_layout = QHBoxLayout()
        self.path_layout.addWidget(self.path_edit)
        self.path_layout.addWidget(self.open_directory_button)
        self.main_layout = QVBoxLayout()
        self.main_layout.addLayout(self.path_layout)
        self.frame = QWidget(self)
        self.frame.setLayout(self.main_layout)
        self.setCentralWidget(self.frame)

我看到第二张图片的风格是 "fusion" 所以一个可能的解决方案是:

import sys
from PySide2 import QtWidgets

app = QtWidgets.QApplication(sys.argv)
app.setStyle("fusion") # <----

# ...

你需要使用setStyleSheet,看这个:

open_directory_button = QtWidgets.QPushButton()
open_directory_button.setStyleSheet("QPushButton:pressed{image:url(C:\image.png); border:none} QPushButton:hover{image:url(C:\image_hover.png); border:none}")