Note. I use Python 3.6.2 and PyQt5, although the logic in the example remains the same and can be understood even if you use other versions of Python and PyQt.
See what is said here:
0, . . , , , .
- x.setMinimumWidth() , :
x.setMinimumWidth(1)
, , ,
x.setMinimumWidth(0)
: ( , ), 32 , .
,
m.setCollapsible(0, False)
m.setCollapsible(1, False)
, . .
, , - sizeHint() , , ( ButtonWrapper , , ).
from PyQt5.QtWidgets import (
QPushButton,
QSplitter,
QWidget,
QApplication,
)
import sys
class ButtonWrapper(QPushButton):
def sizeHint(self):
return self.minimumSize()
class Example(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.resize(400, 400)
m = QSplitter(self)
m.resize(200, 100)
x = ButtonWrapper(self)
x.setGeometry(0, 0, 100, 100)
y = QPushButton(self)
y.setGeometry(0, 100, 100, 100)
m.addWidget(x)
m.addWidget(y)
m.setSizes([20, 180])
print(x.width())
print(x.minimumWidth())
print(x.sizeHint().width())
print(x.minimumSizeHint().width())
self.setWindowTitle('Example')
self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
, -, , , , . , -