本文整理汇总了Python中PyQt5.QtWidgets.QButtonGroup.removeButton方法的典型用法代码示例。如果您正苦于以下问题:Python QButtonGroup.removeButton方法的具体用法?Python QButtonGroup.removeButton怎么用?Python QButtonGroup.removeButton使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QButtonGroup
的用法示例。
在下文中一共展示了QButtonGroup.removeButton方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ToggleToolBar
# 需要导入模块: from PyQt5.QtWidgets import QButtonGroup [as 别名]
# 或者: from PyQt5.QtWidgets.QButtonGroup import removeButton [as 别名]
class ToggleToolBar(QWidget):
index = 0
buttons = []
rows = []
maxRow = 7
maxCol = 4
selectedFrame = []
selectedButtons = []
def __init__(self):
super(ToggleToolBar, self).__init__()
self.setFixedSize(300,560)
self.container = QVBoxLayout()
self.container.setAlignment(Qt.AlignLeft)
self.container.setSpacing(5)
for i in range(0,self.maxRow):
row = QHBoxLayout()
row.setAlignment(Qt.AlignTop)
row.setSpacing(5)
self.container.addLayout(row)
self.rows.append(row)
self.buttonGroup = QButtonGroup()
self.buttonGroup.setExclusive(False)
self.setLayout(self.container)
self.buttonGroup.buttonClicked[int].connect(self.imageSelected)
def imageSelected(self,imgId):
button = self.buttons[imgId]
if button.pixMap in self.selectedFrame and (not button.isChecked()):
self.selectedFrame.remove(button.pixMap)
self.selectedButtons.remove(button)
if (not (button.pixMap in self.selectedFrame)) and button.isChecked():
self.selectedFrame.append(button.pixMap)
self.selectedButtons.append(button)
def getSelected(self):
return self.selectedFrame
def clearAllSelected(self):
for button in self.selectedButtons:
button.setChecked(False)
self.selectedButtons = []
self.selectedFrame = []
def addImageButton(self,image):
imageButton = ImageToggleButton(self.index,image)
self.buttonGroup.addButton(imageButton,self.index)
self.rows[self.index//self.maxCol].addWidget(imageButton)
self.buttons.append(imageButton)
self.index += 1
def createImageButtons(self,imagePath):
groupImg = QImage(imagePath)
width = groupImg.width()
height = groupImg.height()
frameSize = width
for i in range(0,height//width):
img = groupImg.copy(0,i*frameSize,frameSize,frameSize);
self.addImageButton(img)
def removeAllButton(self):
for i in range(0,self.index):
row = self.rows[i // self.maxCol]
row.removeWidget(self.buttons[i])
self.buttonGroup.removeButton(self.buttons[i])
self.buttons[i].close()
self.buttons = []
self.index = 0