pyqt5 QPushButtone стиль наведения, когда он плоский = True - PullRequest
0 голосов
/ 06 августа 2020

Я хочу создать стиль наведения для QPushButton Когда он плоский, возможно ли это ?. Кажется, что наведение не отображается с плоским экраном. Если нет, как я могу сделать похожий плоский стиль с помощью QPushButton с наведением.

import sys
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton
from PyQt5.QtGui import QIcon
from PyQt5.QtCore import pyqtSlot

class App(QWidget):

    def __init__(self):
        super().__init__()
        self.title = 'PyQt5 button - pythonspot.com'
        self.left = 10
        self.top = 10
        self.width = 320
        self.height = 200
        self.initUI()
    
    def initUI(self):
        self.setWindowTitle(self.title)
        self.setGeometry(self.left, self.top, self.width, self.height)
        
        self.button = QPushButton('PyQt5 button', self, flat=True)
        self.button.setStyleSheet(""" QPushButton {
                                                                background-color: yellow;
                                                                }
                                                                
                                                                QPushButton#pushButton:hover {
                                                                    background-color: blue;
                                                                }
                                                                
                                                                QPushButton#pushButton:pressed {
                                                                    background-color: orange;     
                                                                }"""
                                                            )
        self.button.move(100,70)
        self.button.clicked.connect(self.on_click)
        
        self.show()

    @pyqtSlot()
    def on_click(self):
        print('PyQt5 button click')

if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = App()
    sys.exit(app.exec_())

1 Ответ

0 голосов
/ 06 августа 2020

Вот простой пример, как сделать плоскую кнопку с наведением

self.button = QPushButton('PyQt5 button',self)
self.button.setStyleSheet(open('style.css').read())

И стиль. css

QPushButton {
    padding: 5px;
    border-color: black;
    border-style: outset;
    border-width: 2px;
    color: black;
    background-color: yellow;
}
QPushButton:hover {
    background-color: blue;
}
QPushButton:pressed {
    background-color: orange;     
}

Ссылка на документацию для чтения больше возможностей.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...