本文整理汇总了Python中PyQt4.QtGui.QButtonGroup.removeButton方法的典型用法代码示例。如果您正苦于以下问题:Python QButtonGroup.removeButton方法的具体用法?Python QButtonGroup.removeButton怎么用?Python QButtonGroup.removeButton使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtGui.QButtonGroup
的用法示例。
在下文中一共展示了QButtonGroup.removeButton方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TabBarWidget
# 需要导入模块: from PyQt4.QtGui import QButtonGroup [as 别名]
# 或者: from PyQt4.QtGui.QButtonGroup import removeButton [as 别名]
class TabBarWidget(QWidget):
"""
A tab bar widget using tool buttons as tabs.
"""
# TODO: A uniform size box layout.
currentChanged = Signal(int)
def __init__(self, parent=None, **kwargs):
QWidget.__init__(self, parent, **kwargs)
layout = QVBoxLayout()
layout.setContentsMargins(0, 0, 0, 0)
layout.setSpacing(0)
self.setLayout(layout)
self.setSizePolicy(QSizePolicy.Fixed,
QSizePolicy.Expanding)
self.__tabs = []
self.__currentIndex = -1
self.__changeOnHover = False
self.__iconSize = QSize(26, 26)
self.__group = QButtonGroup(self, exclusive=True)
self.__group.buttonPressed[QAbstractButton].connect(
self.__onButtonPressed
)
self.setMouseTracking(True)
self.__sloppyButton = None
self.__sloppyRegion = QRegion()
self.__sloppyTimer = QTimer(self, singleShot=True)
self.__sloppyTimer.timeout.connect(self.__onSloppyTimeout)
def setChangeOnHover(self, changeOnHover):
"""
If set to ``True`` the tab widget will change the current index when
the mouse hovers over a tab button.
"""
if self.__changeOnHover != changeOnHover:
self.__changeOnHover = changeOnHover
def changeOnHover(self):
"""
Does the current tab index follow the mouse cursor.
"""
return self.__changeOnHover
def count(self):
"""
Return the number of tabs in the widget.
"""
return len(self.__tabs)
def addTab(self, text, icon=None, toolTip=None):
"""
Add a new tab and return it's index.
"""
return self.insertTab(self.count(), text, icon, toolTip)
def insertTab(self, index, text, icon=None, toolTip=None):
"""
Insert a tab at `index`
"""
button = TabButton(self, objectName="tab-button")
button.setSizePolicy(QSizePolicy.Expanding,
QSizePolicy.Expanding)
button.setIconSize(self.__iconSize)
button.setMouseTracking(True)
self.__group.addButton(button)
button.installEventFilter(self)
tab = _Tab(text, icon, toolTip, button, None, None)
self.layout().insertWidget(index, button)
self.__tabs.insert(index, tab)
self.__updateTab(index)
if self.currentIndex() == -1:
self.setCurrentIndex(0)
return index
def removeTab(self, index):
"""
Remove a tab at `index`.
"""
if index >= 0 and index < self.count():
self.layout().takeItem(index)
tab = self.__tabs.pop(index)
self.__group.removeButton(tab.button)
tab.button.removeEventFilter(self)
if tab.button is self.__sloppyButton:
self.__sloppyButton = None
self.__sloppyRegion = QRegion()
#.........这里部分代码省略.........
示例2: OptionWidget
# 需要导入模块: from PyQt4.QtGui import QButtonGroup [as 别名]
# 或者: from PyQt4.QtGui.QButtonGroup import removeButton [as 别名]
class OptionWidget(EditorWidget):
widgettype = 'Option Row'
def __init__(self, *args, **kwargs):
super(OptionWidget, self).__init__(*args, **kwargs)
self._bindvalue = None
self.group = QButtonGroup()
self.group.buttonClicked.connect(self.emitvaluechanged)
def createWidget(self, parent=None):
widget = QWidget(parent)
return widget
def _buildfromlist(self, listconfig, multiselect):
def chunks(l, n):
""" Yield successive n-sized chunks from l.
"""
for i in xrange(0, len(l), n):
yield l[i:i+n]
items = listconfig['items']
wrap = self.config.get('wrap', 0)
showcolor = self.config.get('always_color', False)
if wrap > 0:
rows = list(chunks(items, wrap))
else:
rows = [items]
for rowcount, row in enumerate(rows):
for column, item in enumerate(row):
parts = item.split(';')
data = parts[0]
try:
desc = parts[1]
except IndexError:
desc = data
button = QPushButton()
button.setCheckable(multiselect)
self.group.setExclusive(not multiselect)
icon = QIcon()
try:
path = parts[2]
if path.startswith("#"):
# Colour the button with the hex value.
# If show color is enabled we always show the color regardless of selection.
print showcolor
if not showcolor:
style = """
QPushButton::checked {{
border: 3px solid rgb(137, 175, 255);
background-color: {colour};
}}""".format(colour=path)
else:
style = """
QPushButton::checked {{
border: 3px solid rgb(137, 175, 255);
}}
QPushButton {{
background-color: {colour};
}}""".format(colour=path)
button.setStyleSheet(style)
elif path.endswith("_icon"):
icon = QIcon(":/icons/{}".format(path))
else:
icon = QIcon(path)
except:
icon = QIcon()
button.setCheckable(True)
button.setText(desc)
button.setProperty("value", data)
button.setIcon(icon)
button.setIconSize(QSize(24, 24))
if isinstance(self.widget.layout(), QBoxLayout):
self.widget.layout().addWidget(button)
else:
self.widget.layout().addWidget(button, rowcount, column)
self.group.addButton(button)
def initWidget(self, widget, config):
if not widget.layout():
widget.setLayout(QGridLayout())
widget.layout().setContentsMargins(0, 0, 0, 0)
def updatefromconfig(self):
super(OptionWidget, self).updatefromconfig()
for button in self.group.buttons():
self.group.removeButton(button)
self.widget.layout().removeWidget(button)
button.deleteLater()
button.setParent(None)
listconfig = self.config['list']
multiselect = self.config.get('multi', False)
self._buildfromlist(listconfig, multiselect)
super(OptionWidget, self).endupdatefromconfig()
#.........这里部分代码省略.........
示例3: OptionWidget
# 需要导入模块: from PyQt4.QtGui import QButtonGroup [as 别名]
# 或者: from PyQt4.QtGui.QButtonGroup import removeButton [as 别名]
class OptionWidget(EditorWidget):
widgettype = 'Option Row'
def __init__(self, *args):
super(OptionWidget, self).__init__(*args)
self._bindvalue = None
self.group = QButtonGroup()
self.group.setExclusive(True)
self.group.buttonClicked.connect(self.emitvaluechanged)
def createWidget(self, parent):
widget = QWidget(parent)
return widget
def _buildfromlist(self, listconfig):
items = listconfig['items']
for item in items:
parts = item.split(';')
data = parts[0]
try:
desc = parts[1]
except IndexError:
desc = data
button = QPushButton()
icon = QIcon()
try:
path = parts[2]
if path.startswith("#"):
# Colour the button with the hex value
style = """
QPushButton:checked {{
border: 3px solid rgb(137, 175, 255);
background-color: {colour};
}}""".format(colour=path)
button.setStyleSheet(style)
elif path.endswith("_icon"):
icon = QIcon(":/icons/{}".format(path))
else:
icon = QIcon(path)
except:
icon = QIcon()
button.setCheckable(True)
button.setText(desc)
button.setProperty("value", data)
button.setIcon(icon)
button.setIconSize(QSize(24, 24))
self.widget.layout().addWidget(button)
self.group.addButton(button)
def initWidget(self, widget):
if not widget.layout():
widget.setLayout(QHBoxLayout())
widget.layout().setContentsMargins(0, 0, 0, 0)
def updatefromconfig(self):
super(OptionWidget, self).updatefromconfig()
for button in self.group.buttons():
self.group.removeButton(button)
self.widget.layout().removeWidget(button)
button.deleteLater()
button.setParent(None)
listconfig = self.config['list']
self._buildfromlist(listconfig)
super(OptionWidget, self).endupdatefromconfig()
def validate(self, *args):
button = self.group.checkedButton()
if button:
return True
return False
@property
def nullvalues(self):
return ['NULL']
def setvalue(self, value):
if value in self.nullvalues:
value = None
for button in self.group.buttons():
buttonvalue = button.property("value")
if (value is None and buttonvalue in self.nullvalues) or buttonvalue == str(value):
button.setChecked(True)
self.emitvaluechanged()
return
def value(self):
button = self.group.checkedButton()
if not button:
return None
value = button.property("value")
#.........这里部分代码省略.........
示例4: XNavigationEdit
# 需要导入模块: from PyQt4.QtGui import QButtonGroup [as 别名]
# 或者: from PyQt4.QtGui.QButtonGroup import removeButton [as 别名]
#.........这里部分代码省略.........
return path.split(self.separator())
def partsWidget( self ):
"""
Returns the widget that contains the parts system.
:return <QScrollArea>
"""
return self._partsWidget
def startEdit( self ):
"""
Rebuilds the pathing based on the parts.
"""
self._originalText = self.text()
self.scrollWidget().hide()
self.setFocus()
self.selectAll()
def rebuild( self ):
"""
Rebuilds the parts widget with the latest text.
"""
navitem = self.currentItem()
if ( navitem ):
navitem.initialize()
self.setUpdatesEnabled(False)
self.scrollWidget().show()
self._originalText = ''
partsw = self.partsWidget()
for button in self._buttonGroup.buttons():
self._buttonGroup.removeButton(button)
button.close()
button.setParent(None)
button.deleteLater()
# create the root button
layout = partsw.layout()
parts = self.parts()
button = QToolButton(partsw)
button.setAutoRaise(True)
button.setMaximumWidth(12)
button.setArrowType(Qt.RightArrow)
button.setProperty('path', wrapVariant(''))
button.setProperty('is_completer', wrapVariant(True))
last_button = button
self._buttonGroup.addButton(button)
layout.insertWidget(0, button)
# check to see if we have a navigation model setup
if ( self._navigationModel ):
last_item = self._navigationModel.itemByPath(self.text())
show_last = last_item and last_item.rowCount() > 0
else:
show_last = False
# load the navigation system
count = len(parts)
for i, part in enumerate(parts):
path = self.separator().join(parts[:i+1])
示例5: DBDatabasesWidget
# 需要导入模块: from PyQt4.QtGui import QButtonGroup [as 别名]
# 或者: from PyQt4.QtGui.QButtonGroup import removeButton [as 别名]
class DBDatabasesWidget(QWidget):
"""Displays a list of Databases"""
def __init__(self, parent=None):
QWidget.__init__(self, parent)
self.debug = False
self.db = None
self.setWindowTitle("Databases")
#s#elf.setWindowFlags(self.windowFlags() | QtCore.Qt.WindowStaysOnTopHint)
self.mainLayout = QVBoxLayout()
self.mainLayout.setContentsMargins(0, 0, 0, 0)
self.mainLayout.setSpacing(0)
self.setLayout(self.mainLayout)
#=============================================
## Top Toolbar
topBar = QToolBar()
topBar.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
self.mainLayout.addWidget(topBar)
## Add the action buttons
topBar.addAction(Ico.icon(Ico.ServerAdd), "Add", self.on_server_add)
self.actionServerEdit = topBar.addAction(Ico.icon(Ico.ServerEdit), "Edit", self.on_server_edit)
self.actionServerDelete = topBar.addAction(Ico.icon(Ico.ServerDelete), "Delete", self.on_server_delete)
#=============================================
## Tree
self.tree = QTreeWidget()
self.mainLayout.addWidget(self.tree)
self.tree.setHeaderLabels(["Server", "User", ""])
self.tree.setUniformRowHeights(True)
self.tree.setRootIsDecorated(False)
self.tree.setColumnWidth(C.widget, 20)
self.connect( self.tree, SIGNAL( 'itemSelectionChanged()' ), self.on_tree_selection_changed )
self.connect( self.tree, SIGNAL( 'itemDoubleClicked (QTreeWidgetItem *,int)' ), self.on_tree_double_clicked )
self.buttGroup = QButtonGroup(self)
self.connect(self.buttGroup, SIGNAL("buttonClicked(QAbstractButton*)"), self.on_open_server)
self.on_tree_selection_changed()
self.load_servers()
#=======================================
##== Tree Events
def on_tree_selection_changed(self):
disabled = self.tree.selectionModel().hasSelection() == False
self.actionServerEdit.setDisabled(disabled)
self.actionServerDelete.setDisabled(disabled)
def on_tree_double_clicked(self):
self.actionServerEdit.trigger()
#=======================================
## Server Actions
def on_server_add(self):
self.show_server_dialog(None)
def on_server_edit(self):
item = self.tree.currentItem()
if item == None:
return
server = str(item.text(C.server))
self.show_server_dialog(server)
def show_server_dialog(self, server=None):
d = DBServerDialog.DBServerDialog(self, server)
if d.exec_():
self.load_servers()
def on_open_server(self, butt):
self.emit(SIGNAL("open_server"), butt.property("server").toString())
def load_servers(self):
"""Load servers from :py:meth:`pyqtdb.XSettings.XSettings.get_servers` """
self.tree.clear()
for butt in self.buttGroup.buttons():
self.buttGroup.removeButton(butt)
for srv in G.settings.get_servers_list():
item = QTreeWidgetItem()
item.setText(C.server, srv['server'])
item.setText(C.user, srv['user'])
#.........这里部分代码省略.........
示例6: DBServersWidget
# 需要导入模块: from PyQt4.QtGui import QButtonGroup [as 别名]
# 或者: from PyQt4.QtGui.QButtonGroup import removeButton [as 别名]
class DBServersWidget(QWidget):
"""Displays a list of servers"""
def __init__(self, parent=None):
QWidget.__init__(self, parent)
self.debug = False
self.connections = {}
self.setWindowTitle("Servers")
#s#elf.setWindowFlags(self.windowFlags() | QtCore.Qt.WindowStaysOnTopHint)
self.mainLayout = QVBoxLayout()
self.mainLayout.setContentsMargins(0, 0, 0, 0)
self.mainLayout.setSpacing(0)
self.setLayout(self.mainLayout)
#=============================================
## Top Toolbar
topBar = QToolBar()
topBar.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
self.mainLayout.addWidget(topBar)
## Add the action buttons
topBar.addAction(Ico.icon(Ico.ServerAdd), "Add", self.on_server_add)
self.actionServerEdit = topBar.addAction(Ico.icon(Ico.ServerEdit), "Edit", self.on_server_edit)
self.actionServerDelete = topBar.addAction(Ico.icon(Ico.ServerDelete), "Delete", self.on_server_delete)
#=============================================
## Tree
self.tree = QTreeWidget()
self.mainLayout.addWidget(self.tree)
self.tree.setUniformRowHeights(True)
self.tree.setRootIsDecorated(True)
self.tree.setHeaderLabels(["Server", "Butt"]) # set header, but hide anyway
self.tree.header().hide()
self.tree.header().setResizeMode(C.node, QHeaderView.Stretch)
self.tree.setColumnWidth(C.butt, 20)
self.connect( self.tree, SIGNAL( 'itemSelectionChanged()' ), self.on_tree_selection_changed )
self.connect( self.tree, SIGNAL( 'itemDoubleClicked (QTreeWidgetItem *,int)' ), self.on_tree_double_clicked )
self.buttGroup = QButtonGroup(self)
self.connect(self.buttGroup, SIGNAL("buttonClicked(QAbstractButton*)"), self.on_open_server)
self.on_tree_selection_changed()
self.load_servers()
#=======================================
##== Tree Events
def on_tree_selection_changed(self):
disabled = self.tree.selectionModel().hasSelection() == False
self.actionServerEdit.setDisabled(disabled)
self.actionServerDelete.setDisabled(disabled)
def on_tree_double_clicked(self):
self.actionServerEdit.trigger()
#=======================================
## Server Actions
def on_server_add(self):
self.show_server_dialog(None)
def on_server_edit(self):
item = self.tree.currentItem()
if item == None:
return
server = str(item.text(C.server))
self.show_server_dialog(server)
def show_server_dialog(self, server=None):
d = DBServerDialog.DBServerDialog(self, server)
if d.exec_():
self.load_servers()
def load_servers(self):
"""Load servers from :py:meth:`pyqtdb.XSettings.XSettings.get_servers` """
self.tree.clear()
for butt in self.buttGroup.buttons():
self.buttGroup.removeButton(butt)
for srv in G.settings.get_servers_list():
item = QTreeWidgetItem()
item.setText(C.node, srv['server'])
#.........这里部分代码省略.........