QHBoxLayout中最小宽度的QPushButton?

时间:2018-04-04 12:55:10

标签: qt qt5 qpushbutton qlayout

我想用文本" X"创建QPushButton。关上窗户。我想把它放在按钮的栏上。为此,我制作了QHLayout。

layTop=QHBoxLayout()

self.btnMenu=QPushButton("Menu") #just as sample of button with normal size
layTop.addWidget(self.btnMenu)

btnX=QPushButton("X")  #I need it small
btnX.setSizePolicy(QSizePolicy.Minimum,QSizePolicy.Preferred) #I try this, but it's not work as I expected
layTop.addWidget(btnX)

但是," X"按钮和其他按钮一样大。如何缩小?

(此代码的屏幕截图如下)

expectation-vs-reality for SizePolicy

1 个答案:

答案 0 :(得分:1)

使用QToolButon代替QPushButton

enter image description here