- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
抱歉,我的问题可能听起来很愚蠢,但坦白说,我在互联网上花了很多时间试图找出如何将小部件s添加到 QMdiSubWindow,我的意思是多个小部件 不仅仅是一个小部件(这对我来说非常重要..我需要我的子窗口包含多个小部件而不是单个小部件)。
例如,我想将此小部件和布局添加到我的子窗口:
QVbox 包含 QlineEdit 和按钮,QHbox 包含按钮 ...
it doesn't matter if you show me how i could do it using the above example, what really matter is to show me how no matter what example you use
注意:请使用OOP和Python而不是c++
最佳答案
小部件和布局的层次结构应始终遵循
widget -> layout -> widget -> layout -> widget -> ...
其中每个小部件只能有一个布局,但每个布局可以包含多个小部件(请注意,为简单起见,上面只显示每个布局一个小部件)。
因此,您需要做的是创建一个包含布局的小部件,并且该布局包含 QPushButton 和 QLineEdit`。例如:
# construct the top level widget
widget = QWidget()
# construct the top level layout
layout = QVBoxLayout(widget)
# create the widgets to add to the layout
button = QPushButton('My Button')
lineedit = QLineEdit()
# add the widgets to the layout
layout.addWidget(button)
layout.addWidget(lineedit)
# set the layout on the widget
widget.setLayout(layout)
# we now have a single widget that contains a layout and 2 widgets
这允许您有效地将多个小部件封装在一个小部件中(这也是许多更复杂的 Qt 小部件在内部创建的方式,例如 QSpinBox
)。因此,如果您想要在上面的布局中添加另一个复杂的小部件,您可以再次制作另一个 widget2 = QWidget()
,创建一个布局(例如 layout2 = QHBoxLayout(widget2)
) ,然后向其中添加多个小部件。完成后,将 widget2
小部件添加到原始布局 (layout.addWidget(widget2)
)。
希望您现在可以了解如何从任意数量的子小部件和布局构造单个复杂的小部件。
此时,您现在可以将单个小部件设置为现有的QMdiSubWIndow
# now add this widget to the QMdiSubWindow
mdisubwindow.setWidget(widget)
或者,调用 QMdiArea
上的便捷函数来使用小部件创建一个新的 QMdiSubWindow
:
mdisubwindow = mdiarea.addSubWindow(widget)
注意:对于您的具体示例,您实际上不需要构造 widget2
来封装 QHBoxLayout
。您可以通过调用 layout.addLayout(layout2)
将 QHBoxLayout
(在上面的粗略示例中为 layout2
)直接添加到原始布局。然而,这更多的是一种特殊情况,一旦您开始创建自己的小部件类以重用代码,上面的交替小部件和布局封装的一般原则就更具有普遍性。
关于python - 如何将小部件放入 PyQt QMdiSubWindow 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37515978/
我试图将FigureCanvasQTAgg放在QMdiSubWindow中,以便用户可以动态创建他/她自己的绘图。我编写了这个非常小的独立代码: from PyQt4 import QtGui fro
有没有办法为子窗口部件(继承自 QMdiSubWindow)定义初始大小?我不想限制最小尺寸或阻止它调整大小,而只是想在第一时间以给定尺寸显示窗口。 我已尝试重新实现 sizeHint 并定义不同的大
当用户关闭 QMdiSubWindow 时,有什么办法可以得到通知吗?我在 QMdiArea 中找不到任何信号也不在 QMdiSubWindow这表明我可以。 我认为我唯一的机会是通过子类化 QMdi
我注意到 QMdiarea 的窗口需要自定义样式。我想删除 QMdiSubWindow 小部件左上角出现的图标,同时将窗口的丑陋蓝色更改为看起来相当不错的颜色。 我已经尝试了 setWindowsfl
我有一个 QWidget 子类的指针: QWidget * 表单; 接下来我把子类的实例作为QMdiSubWindow的内部小部件: QMdiSubWindow * w = mdiArea->addS
我有一个带有 QMDIArea 的应用程序,我在 QMDIArea 中添加了两个子窗口(PhoneBook 窗口和状态窗口)。 PhoneBook 子窗口有最大化、最小化和关闭按钮。Status 子窗
抱歉,我的问题可能听起来很愚蠢,但坦白说,我在互联网上花了很多时间试图找出如何将小部件s添加到 QMdiSubWindow,我的意思是多个小部件 不仅仅是一个小部件(这对我来说非常重要..我需要我的子
我想自定义 QMdiSubWindow 的标题栏。 为此,我使用 qss。 QMdiSubWindow { border: 1px solid #000000; background: #000000
尝试从 QMdiSubWindow 中删除 Qt 图标,但收效甚微。下图显示了左上角的图标。 这是一些代码,它似乎应该将图标设置为空,但实际上没有。 QMdiSubWindow* sub = new
我正在编写某种编辑器,我希望允许用户在 MdiArea 内自由移动窗口,并允许他们将窗口移出 MdiArea、移出应用程序的主窗口。 我应该怎样做才能实现这个目标? 最佳答案 我设法找到了一个适用于
我正在使用 Qt 应用程序并尝试通过辅助功能界面实现 UI 自动化。这一切都很好,除了这个应用程序有一个包含 QMdiSubWindow 的 QMdiArea 并且这些子窗口中包含的任何内容对自动化界
我是一名优秀的程序员,十分优秀!