我正在使用PyQT4
为一位潜在客户创建一个示例应用程序。我正在寻找一种方法来给特定的部件添加边框。请给我一些提示。
更新:
class CentralWidget(QtGui.QWidget):
def __init__(self, mainWindow):
super(CentralWidget, self).__init__()
self.create(mainWindow)
上述代码定义了小部件。
根据样式表文档,QWidget不支持border属性。
你需要使用类似QFrame的东西:
这里有一个完整的例子
from PyQt4 import QtGui,QtCore
class CentralWidget(QtGui.QFrame):
def __init__(self, *args):
super(CentralWidget, self).__init__(*args)
self.setStyleSheet("background-color: rgb(255,0,0); margin:5px; border:1px solid rgb(0, 255, 0); ")
if __name__ == '__main__':
import sys
app = QtGui.QApplication(sys.argv)
mw = QtGui.QMainWindow()
w = CentralWidget(mw)
mw.setCentralWidget(w)
mw.show()
w.show()
app.exec_()
self.setFrameStyle(QFrame.StyledPanel | QFrame.Plain)
self.setLineWidth(1)
欲了解更多信息,请查看以下链接:https://doc.qt.io/qtforpython-5/PySide2/QtWidgets/QFrame.html
setFrameStyle()
方法似乎效果很好。 - Vijay Shanker Dubey"QFrame {background-color: rgb(255,0,0);}"
。 - Stephen Terry