本文整理汇总了Python中qtpy.QtWidgets.QPushButton.setFixedSize方法的典型用法代码示例。如果您正苦于以下问题:Python QPushButton.setFixedSize方法的具体用法?Python QPushButton.setFixedSize怎么用?Python QPushButton.setFixedSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qtpy.QtWidgets.QPushButton
的用法示例。
在下文中一共展示了QPushButton.setFixedSize方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TabBarPlus
# 需要导入模块: from qtpy.QtWidgets import QPushButton [as 别名]
# 或者: from qtpy.QtWidgets.QPushButton import setFixedSize [as 别名]
class TabBarPlus(QTabBar):
"""Tab bar that has a plus button floating to the right of the tabs."""
plusClicked = Signal()
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# Plus Button
self.plusButton = QPushButton("+")
self.plusButton.setParent(self)
self.plusButton.setFixedSize(20, 20) # Small Fixed size
self.plusButton.clicked.connect(self.plusClicked.emit)
self.movePlusButton() # Move to the correct location
# end Constructor
def sizeHint(self):
"""Return the size of the TabBar with increased width for the plus button."""
sizeHint = QTabBar.sizeHint(self)
width = sizeHint.width()
height = sizeHint.height()
return QSize(width+25, height)
# end tabSizeHint
def resizeEvent(self, event):
"""Resize the widget and make sure the plus button is in the correct location."""
super().resizeEvent(event)
self.movePlusButton()
# end resizeEvent
def tabLayoutChange(self):
"""This virtual handler is called whenever the tab layout changes.
If anything changes make sure the plus button is in the correct location.
"""
super().tabLayoutChange()
self.movePlusButton()
# end tabLayoutChange
def movePlusButton(self):
"""Move the plus button to the correct location."""
# Find the width of all of the tabs
size = sum([self.tabRect(i).width() for i in range(self.count())])
# size = 0
# for i in range(self.count()):
# size += self.tabRect(i).width()
# Set the plus button location in a visible area
h = self.geometry().top()
w = self.width()
if size > w: # Show just to the left of the scroll buttons
self.plusButton.move(w-54, h)
else:
self.plusButton.move(size, h)
示例2: Dimension
# 需要导入模块: from qtpy.QtWidgets import QPushButton [as 别名]
# 或者: from qtpy.QtWidgets.QPushButton import setFixedSize [as 别名]
class Dimension(QWidget):
stateChanged = Signal(int)
valueChanged = Signal()
"""
pass in dimension
state: one of (State.X, State.Y, State.NONE, State.DISBALE)
Can be run independently by:
from mantidqt.widgets.sliceviewer.dimensionwidget import Dimension
from qtpy.QtWidgets import QApplication
app = QApplication([])
window = Dimension({'minimum':-1.1, 'number_of_bins':11, 'width':0.2, 'name':'Dim0', 'units':'A'})
window.show()
app.exec_()
"""
def __init__(self, dim_info, number=0, state=State.NONE, parent=None):
super(Dimension, self).__init__(parent)
self.minimum = dim_info['minimum']
self.nbins = dim_info['number_of_bins']
self.width = dim_info['width']
self.number = number
self.layout = QHBoxLayout(self)
self.name = QLabel(dim_info['name'])
self.units = QLabel(dim_info['units'])
self.x = QPushButton('X')
self.x.setFixedSize(32,32)
self.x.setCheckable(True)
self.x.clicked.connect(self.x_clicked)
self.y = QPushButton('Y')
self.y.setFixedSize(32,32)
self.y.setCheckable(True)
self.y.clicked.connect(self.y_clicked)
self.slider = QSlider(Qt.Horizontal)
self.slider.setRange(0, self.nbins-1)
self.slider.valueChanged.connect(self.slider_changed)
self.spinbox = QDoubleSpinBox()
self.spinbox.setDecimals(3)
self.spinbox.setRange(self.get_bin_center(0), self.get_bin_center(self.nbins-1))
self.spinbox.setSingleStep(self.width)
self.spinbox.valueChanged.connect(self.spinbox_changed)
self.layout.addWidget(self.name)
self.layout.addWidget(self.x)
self.layout.addWidget(self.y)
self.layout.addWidget(self.slider, stretch=1)
self.layout.addStretch(0)
self.layout.addWidget(self.spinbox)
self.layout.addWidget(self.units)
self.set_value(0)
if self.nbins < 2:
state = State.DISABLE
self.set_state(state)
def set_state(self, state):
self.state = state
if self.state == State.X:
self.x.setChecked(True)
self.y.setChecked(False)
self.slider.hide()
self.spinbox.hide()
self.units.hide()
elif self.state == State.Y:
self.x.setChecked(False)
self.y.setChecked(True)
self.slider.hide()
self.spinbox.hide()
self.units.hide()
elif self.state == State.NONE:
self.x.setChecked(False)
self.y.setChecked(False)
self.slider.show()
self.spinbox.show()
self.units.show()
else:
self.x.setChecked(False)
self.x.setDisabled(True)
self.y.setChecked(False)
self.y.setDisabled(True)
self.slider.hide()
self.spinbox.show()
self.spinbox.setDisabled(True)
self.units.show()
def get_state(self):
return self.state
def x_clicked(self):
old_state = self.state
#.........这里部分代码省略.........