我的应用程序需要一个标题中带有按钮的组框。 或者类似的东西。
这是我的用例。
该应用程序读取数据结构并从中构建一个属性面板。可以通过此属性面板添加/删除某些属性。
如果属性是终端,例如字符串或整数,则该属性将表示为经典标签加上适当的小部件。我可以轻松地向此布局添加删除按钮。
但是如果属性更复杂并且本身具有一些子属性,则它会表示为组框。原始的 QGroupBox 只允许一个字符串作为标题,而我想在那里添加一个删除按钮。
我是 QT 新手,可能会遗漏一些东西,有什么想法吗?
I need for my app a groupbox with a button in title. Or something equivalent.
Here is my usecase.
The app reads a datastructure and build a propery panel out of it. Some properties can be added/removed via this property panel.
If a property is a terminal, like a string or an integer, the property is represented as a classic label plus the proper widget. I can easily add a delete button to this layout.
But if a property is more complex and has itself some subproperties, it is represented as a groupbox. The original QGroupBox allow only a string as a title while I would like to add a delete button there.
I am new to QT and may be missing something, any idea ?
发布评论
评论(2)
PyQt 附带的小部件是基本构建块和方便的小部件,可满足常见用法和需求。但是,当您开始需要自定义小部件时,您就可以自由地对相近的东西进行子类化,并编写您自己的自定义小部件。
让我们以 QGroupBox 为例。它基本上是一个由顶部的 QLabel 组成的 QFrame。然后该类包装了一些方法,允许您设置该标签的文本。这个基本的小部件将像这样开始:
我们可以做的是采用一个 QWidget,并添加一个带有空白标签的 QGroupBox。然后将按钮放置在父窗口小部件的绝对位置。我们本可以使用 QFrame,但使用 QGroupBox 可以让您立即获得所需的样式。
您可以使用可更改按钮文本的方法来扩展此自定义类。顶部小部件的边距是必要的,以便为您提供额外的空间来在 GroupBox 上方布局按钮
The widgets that come stock with PyQt are you basic building blocks and convenience widgets to cover the common usages and needs. But when you start to want custom widgets, you then have the freedom to subclass something that is close, and compose your own custom widgets.
Lets take the QGroupBox. Its basically a QFrame composed with a QLabel at the top. Then the class wraps some methods that allow you to set the text of this label. This basic widget would start out like:
What we can do instead is take a QWidget, and add a QGroupBox with a blank label. And then place a button at an absolute position to the parent widget. We could have used a QFrame but using a QGroupBox gets you the instant styling you wanted.
You can expand this custom class with methods that let you change the text of the button. The margin of the widget at the top is neccessary to give you the extra space to layout the button above the GroupBox
实际上,
QGroupBox
类允许您通过可检查属性。当用户与复选框交互时,会发出以下信号:
PyQt。
Actually, the
QGroupBox
class allows you to place a check box next to the label via checkable property.When the user interacts with the check box, it will emits the following signals:
The corresponding methods and signals are equal in PyQt.