pyqt5 QPushButtone 平放时悬停样式=True
pyqt5 QPushButtone hover style when it's flat=True
我想做一个QPushButton的悬停样式,当它是平的时候,可以吗?。似乎 hover 没有显示为 flat。如果没有,我如何使用带悬停的 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_())
这是一个简单的例子,如何制作带有悬停的平面按钮
self.button = QPushButton('PyQt5 button',self)
self.button.setStyleSheet(open('style.css').read())
和style.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;
}
Link 到 documentation 阅读更多选项。
我想做一个QPushButton的悬停样式,当它是平的时候,可以吗?。似乎 hover 没有显示为 flat。如果没有,我如何使用带悬停的 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_())
这是一个简单的例子,如何制作带有悬停的平面按钮
self.button = QPushButton('PyQt5 button',self)
self.button.setStyleSheet(open('style.css').read())
和style.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;
}
Link 到 documentation 阅读更多选项。