0
我有以下pyside部件代碼:pyside QT4,alligningment語法誤解
class NavigationHeadWidget(QWidget):
def __init__(self):
QWidget.__init__(self)
self._current_page = 0
self._last_page = 0
self._pageination_string = "page %s of %s"
self._pagination_label = QLabel()
self._pagination_label.setText(self._pageination_string % (str(self._current_page), str(self._last_page)))
self.setMinimumWidth(400)
self._header_buttons_prev = QPushButton("b_prev")
self._header_buttons_next = QPushButton("b_next")
self._header_buttons_prev.setText("prev")
self._header_buttons_next.setText("next")
self._header_buttons_next.setMaximumWidth(40)
self._header_buttons_prev.setMaximumWidth(40)
self._layout = QHBoxLayout()
self._layout.addWidget(self._header_buttons_prev,Qt.AlignLeft)
self._layout.addWidget(self._pagination_label,Qt.AlignCenter)
self._layout.addWidget(self._header_buttons_next,Qt.AlignRight)
self.setLayout(self._layout)
導致:
我希望文字的按鈕之間的中心,但它留下alligns。
如果我註釋掉的標籤,我得到:
我希望留在按鈕和右神韻:,但他們似乎並沒有這樣做。
什麼是正確的語法來獲得我想要的行爲?
另外我如何讓按鈕自動調整到它包含的文本的大小?必須在上面的代碼中硬編碼大小。
謝謝。我是否也按照相同的按鈕來讓他們行爲? :D – 2012-07-06 15:06:31
我已經擴展了我的答案,詳細介紹了使用墊片的情況。這樣,無論標籤是否存在,按鈕始終保持左/右對齊。 – mata 2012-07-06 15:28:17