正方形のPushButton


文字の左右の空白が邪魔だったので、sizeHintを変更。
ただし、当然はみ出た文字は見えなくなる。

from PyQt4.QtCore import *
from PyQt4.QtGui import *

class SquareButton(QPushButton):
    def __init__(self, *a, **kw):
        QPushButton.__init__(self, *a, **kw)
        self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
    
    def sizeHint(self):
        sz = QPushButton.sizeHint(self)
        return QSize(sz.height(), sz.height())
    
def main():
    import sys
    app = QApplication(sys.argv)
    w  = QWidget()
    layout = QHBoxLayout()
    layout.addWidget(SquareButton("A"))
    layout.addWidget(SquareButton("B"))
    layout.addWidget(SquareButton("SPAM"))
    w.setLayout(layout)
    w.show()
    app.exec_()
    
if __name__ == "__main__":
    main()