这是我的第一个问题,我希望尽可能清楚。
我有一个带有两个内部元素的Widget:WidgetA应该在右上角,而WidgetB应该包围第一个(因此其中的文本应该在WidgetA下面)。
这就是我想要实现的目标:
________________________
| _________ _____ |
| | B | | A | |
| | some | |___| |
| | text |--------- |
| | should go here | |
| |_________________| |
|______________________|
你们建议我使用哪种布局? 我应该编写自己的自定义布局吗?
在我的特定情况下,WidgetA是一个QLabel(带有QPixmap),WidgetB是一个QFormLayout(我现在认为这不是一个Widget,但我认为这可能对其他人更有帮助)。
我已经构建了一个代码示例,但这更像是一个设计问题,也许代码并不重要。
from PyQt4 import QtGui, QtCore
class MyWidget(QtGui.QWidget):
def __init__(self, parent=None):
super(MyWidget, self).__init__(parent)
self.layout = QtGui.QVBoxLayout()
self.hLayout = QtGui.QHBoxLayout()
self.smallLabel = QtGui.QLabel("small small")
self.longLabel = QtGui.QLabel('''
very very very very very very very
very very very very very very very
very very very very very very very
long label''')
self.longLabel.setWordWrap(True)
self.hLayout.addWidget(self.longLabel)
self.hLayout.addWidget(self.smallLabel)
self.layout.addLayout(self.hLayout)
self.setLayout(self.layout)
# I run this in Maya, so I don't care about __main__ and apps
w = MyWidget()
w.show()
谢谢!