如何在PYQT中打开多个持久窗口?
我正在尝试在pyqt6/pyside6 qtreeview
中显示JSON元数据。 长度大于1。
如果
def openTreeWidget(app, jmd):
view = QTreeView()
model = JsonModel()
view.setModel(model)
model.load(jmd)
app.w = view # app = `self` of a QMainWindow instance
app.w.show()
for md in jsonMetadataList:
openTreeWidget(self, md)
我的JSON元数据列表的 > JSONMODEL 基于: https:https://doc.qt。 io/qtforpython/tutorials/basicutorial/treewidget.html
我从: htttps”> htttps ://www.pythonguis.com/tutorials/pyqt6-creating-multiple-windows/
在当前案例中,所有弹出式UPS(除一个)暂时打开后关闭。仅JSONMETADATALIST
中的最后一个项目仍显示在持久窗口中。我相信,某种程度上,我不会对以前的Windows进行引用,并在单个小部件上重新打开/重写数据。如何保留参考?
另外,我对pyqt/pyside是非常新的,所以我 在做事,无论他们现在看多么丑陋。当然,这会随着时间的流逝而变得更好:);
I am trying to display JSON metadata in PyQt6/PySide6 QTreeView
. I want to generalize for the case where multiple persistent windows (QtWidgets
) pop up if my JSON metadata list has a length greater than 1.
for example:
def openTreeWidget(app, jmd):
view = QTreeView()
model = JsonModel()
view.setModel(model)
model.load(jmd)
app.w = view # app = `self` of a QMainWindow instance
app.w.show()
for md in jsonMetadataList:
openTreeWidget(self, md)
where TreeItem
and JsonModel
are based on: https://doc.qt.io/qtforpython/tutorials/basictutorial/treewidget.html
I stole the app.w
idea from: https://www.pythonguis.com/tutorials/pyqt6-creating-multiple-windows/
In the current case, all pop ups (except one) close after momentarily opening. Only the last item in jsonMetadataList
remains displayed in a persistent window. I believe that somehow I am not keeping the reference to previous windows and reopening/rewriting data on a single widget. How can I keep the reference?
Also, I am very new to PyQt/PySide so I'm just doing things no matter how ugly they look at the moment. This will, of course, get better with time :);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我设法通过不破坏参考来使它变得更加紧密。这就是我做的。
仍然欢迎更好的想法:)
I managed to bodge it up by not destroying the reference. Here's how I did it.
Better ideas are still welcome :)