我已经在我的主窗口中添加了一个小工具,我想给它一个类似box-shadow: 3px 3px 25px #111;的展示
我尝试了上面的方法,转到widget change stylesheet选项并添加如下代码:
background-color:#fff;
border:4px solid blue;
box-shadow: 0px -3px 5px #a6a6a6;前两个属性给出了预期的效果,但box-shadow不起作用。
如何使用Python QT Designer和添加方框阴影到一个小工具?
发布于 2021-07-23 08:12:31
Qt StyleSheet不是CSS,但它是一种实现了一些功能的技术,其中不是框阴影。如果你想实现类似的东西,那么你应该使用QGraphicsDropShadowEffect:
import sys
from PyQt5.QtCore import QPoint, Qt
from PyQt5.QtGui import QColor
from PyQt5.QtWidgets import (
QApplication,
QGraphicsDropShadowEffect,
QMainWindow,
QVBoxLayout,
QWidget,
)
def main():
app = QApplication(sys.argv)
main_window = QMainWindow()
container = QWidget()
container.setContentsMargins(3, 3, 3, 3)
main_window.setCentralWidget(container)
widget = QWidget()
widget.setAutoFillBackground(True)
lay = QVBoxLayout(container)
lay.addWidget(widget)
effect = QGraphicsDropShadowEffect(
offset=QPoint(3, 3), blurRadius=25, color=QColor("#111")
)
widget.setGraphicsEffect(effect)
main_window.resize(640, 480)
main_window.show()
sys.exit(app.exec_())
if __name__ == "__main__":
main()建议您阅读Qt样式表参考:
https://stackoverflow.com/questions/68492470
复制相似问题