Reputation: 15
I created a small GUI in QtCreator and had it converted to python to execute on a Raspberry Pi. issue is the QSpinBox buttons are only scaled by QSpinBox height. how can i increase the width of the buttons in the python code?
here is the python code that was generated for one of the boxes, SpinBox_7:
self.spinBox_7 = QtWidgets.QSpinBox(self.gridLayoutWidget)
self.spinBox_7.setMinimumSize(QtCore.QSize(0, 50))
palette = QtGui.QPalette()
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Highlight, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.HighlightedText, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Highlight, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.HighlightedText, brush)
brush = QtGui.QBrush(QtGui.QColor(51, 153, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Highlight, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.HighlightedText, brush)
self.spinBox_7.setPalette(palette)
font = QtGui.QFont()
font.setPointSize(20)
font.setBold(False)
font.setWeight(50)
self.spinBox_7.setFont(font)
self.spinBox_7.setAlignment(QtCore.Qt.AlignCenter)
self.spinBox_7.setMaximum(12)
self.spinBox_7.setSingleStep(2)
self.spinBox_7.setObjectName("spinBox_7")
self.gridLayout.addWidget(self.spinBox_7, 2, 3, 1, 1)
Upvotes: 1
Views: 3028
Reputation: 243897
One possible solution is to set the widths using Qt StyleSheet to the down-button and up-button of the QSpinBox:
QSpinBox::down-button{
width: 50
}
QSpinBox::up-button{
width: 50
}
To use it there are at least the following 3 options:
To use a Qt Application you must have a QApplication, then you must set it there:
app = QtWidgets.QApplication(sys.argv)
app.setStyleSheet("""
QSpinBox::down-button{
width: 50
}
QSpinBox::up-button{
width: 50
}""")
Apply it to each QSpinBox:
self.spinBox_7.setStyleSheet("""
QSpinBox::down-button{
width: 50
}
QSpinBox::up-button{
width: 50
}""")
Upvotes: 4