[英]Pyside2 and material design
I'm writing a simple app to control an experimental setup.我正在编写一个简单的应用程序来控制实验设置。 I have most of the important stuff done, and I was thinking that it would be nice to use material design for the UI widgets.我已经完成了大部分重要的工作,我认为为 UI 小部件使用材料设计会很好。
I found this repo that has all the widgets i'd want https://github.com/laserpants/qt-material-widgets , but i have no idea how to import them in my project.我发现这个 repo 包含我想要的所有小部件https://github.com/laserpants/qt-material-widgets ,但我不知道如何在我的项目中导入它们。 I am using Pyside2 and qtDesigner, loading the ui file with QUiLoader, eg:我正在使用 Pyside2 和 qtDesigner,使用 QUiLoader 加载 ui 文件,例如:
class ConsoleWindow(QObject):
def __init__(self, uifilename):
super(ConsoleWindow, self).__init__(None)
self.window = QUiLoader().load( QFile( 'uifile.ui' ) )
self.setupCallbacks()
self.window.installEventFilter(self)
self.window.show()
[...]
Does anyone know how to do it?有谁知道怎么做?
At the moment you only have one option to achieve this, using style sheets for each of the elements you use.目前,您只有一种选择来实现这一目标,即为您使用的每个元素使用样式表。
I found an old repository that tried to provide a set of style rules so you can use them directly into your code, but I don't know how similar they are to a pure-material-design-look.我找到了一个旧的存储库,它试图提供一组样式规则,以便您可以直接在代码中使用它们,但我不知道它们与纯材料设计外观有多相似。
You can either, set style per elements like:您可以为每个元素设置样式,例如:
class MyWidget(QWidget):
def __init__(self):
QWidget.__init__(self)
# Changing background color
self.setStyleSheet("background-color: rgb(0.2, 0.3, 0.8, 0.2);")
or load a general style sheet for your application:或为您的应用程序加载通用样式表:
sheet = ":/some_style_sheet_file.qss"
with open(sheet, "r") as f:
style = f.read()
app = QApplication([])
# ...
app.setStyleSheet(style)
sys.app(app.exec_())
If you want to use Qml on the other hand, you can achieve this easily like this example .另一方面,如果你想使用 Qml,你可以像这个例子一样轻松实现。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.