PYQT5-是否不可能在新小部件中嵌套小部件?

发布于 2025-02-07 01:15:01 字数 1547 浏览 0 评论 0原文

我有单独的脚本设计的框架,这些框架都被调用到此中央GUI脚本上,该脚本表明他们使用QMainWindow如人们所期望的。

但是,我试图以这样的方式重新设计主窗口,以使右侧有一个永久固定的框架,左侧有一个选项卡式框架。

在尝试实现这一目标之前,我可以使用setlayout显示一次Mainwindow上的所有帧,但是,当我尝试将其中几个“ sub-Widget”帧添加到我的新选项卡式框架中时,一切都会变得很烦人。 ..

...有效地,我正在从其他脚本中拨打调用的已运行的小部件(设计w/ qframe),并尝试与它们一起制作2个新的小部件(qtabwidget,for左框架,右框架)。但是,当运行时,窗口将与我的GroupBox和TabWidgets完全空,并且我的“子网络”在新窗口中显示。

这是一个片段:

    tab_frame = QWidget()
    tab_frame.layout = QVBoxLayout() #-------------------- Layout
    tab_frame.layout.addWidget(self.FRAME_FROM_OTHER_SCRIPT)
    tab_frame.layout.addStretch(1)
    
    #### Tabs Parent ####
    tabs = QTabWidget()
    tabs.layout = QVBoxLayout()
    tabs.addTab(tab_frame,"Tab 1")
    
    #### Fixed Frame ####
    vbox_az = QGroupBox()
    vbox_az.layout = Qt.QVBoxLayout() #------------------------ Layout
    vbox_az.layout.addWidget(self.FRAME_FROM_OTHER_SCRIPT)


    self.main_grid = QGridLayout() #--------------------------- Layout
    self.main_grid.addWidget(tabs,0,0,1,2)
    self.main_grid.addWidget(vbox_az,0,2,1,3)

    self.main_grid.setColumnStretch(2,1)
    self.main_grid.setColumnStretch(5,1)
    
    self.main_window.setLayout(self.main_grid)

我不确定实际发生的事情...小部件是否无法嵌套在其他小部件中?

因为SetLayout依赖于布局输入,而不是小部件,所以我不确定除了将我的“子网络”分组为组盒中,我不确定如何攻击此问题,但我不知道为什么这么错了。

这是一个图片屏幕,可以进一步说明: (为了我的问题,我已经要求将窗户分为两部分,尽管我实际上将其分配了三遍)

I have frames designed in seperate scripts that are all called to this central gui script which shows them using QMainWindow as one would expect.

However, I am trying to redesign the Main Window in such a way that there is a permanently fixed frame on the right hand side, and a tabbed frame on the left.

Before I attempted to make this happen, I could display, using setlayout, all of the frames on the mainwindow at once, however, when I try to add several of these"sub-widget" frames to my new tabbed frame everything gets annoying...

... effectively, I am taking already functioning widgets (designed w/ QFrame) called from other scripts and trying to make 2 new widgets with them (QTabWidget, for the left frame, and QGroupBox for the right). However, when run, the window pops up with my groupbox and tabwidgets completely empty, and my "sub-widgets" are displayed in new windows.

Here is a snippet:

    tab_frame = QWidget()
    tab_frame.layout = QVBoxLayout() #-------------------- Layout
    tab_frame.layout.addWidget(self.FRAME_FROM_OTHER_SCRIPT)
    tab_frame.layout.addStretch(1)
    
    #### Tabs Parent ####
    tabs = QTabWidget()
    tabs.layout = QVBoxLayout()
    tabs.addTab(tab_frame,"Tab 1")
    
    #### Fixed Frame ####
    vbox_az = QGroupBox()
    vbox_az.layout = Qt.QVBoxLayout() #------------------------ Layout
    vbox_az.layout.addWidget(self.FRAME_FROM_OTHER_SCRIPT)


    self.main_grid = QGridLayout() #--------------------------- Layout
    self.main_grid.addWidget(tabs,0,0,1,2)
    self.main_grid.addWidget(vbox_az,0,2,1,3)

    self.main_grid.setColumnStretch(2,1)
    self.main_grid.setColumnStretch(5,1)
    
    self.main_window.setLayout(self.main_grid)

I am unsure of what is actually happening... are widgets unable to be nested within other widgets?

Because setLayout relies on a layout input and not a widget I am unsure of how else to attack this problem other than by grouping my "sub-widgets" into groupboxes but I do not know why it's going so wrong.

Here is a picture screen-grab to illustrate further:
(for the sake of my question I have asked to split my window into two portions though I am actually splitting it three times)
enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文