本文整理汇总了Python中PyQt4.QtGui.QTabBar.addTab方法的典型用法代码示例。如果您正苦于以下问题:Python QTabBar.addTab方法的具体用法?Python QTabBar.addTab怎么用?Python QTabBar.addTab使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtGui.QTabBar
的用法示例。
在下文中一共展示了QTabBar.addTab方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ImportWindow
# 需要导入模块: from PyQt4.QtGui import QTabBar [as 别名]
# 或者: from PyQt4.QtGui.QTabBar import addTab [as 别名]
#.........这里部分代码省略.........
self.targetAccountLabel = QtGui.QLabel(tr("Target Account:"))
self.targetAccountLayout.addWidget(self.targetAccountLabel)
self.targetAccountComboBox = QComboBox(self)
self.targetAccountComboBox.setMinimumSize(QtCore.QSize(150, 0))
self.targetAccountLayout.addWidget(self.targetAccountComboBox)
spacerItem = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
self.targetAccountLayout.addItem(spacerItem)
self.groupBox = QGroupBox(tr("Are some fields wrong? Fix them!"))
self.gridLayout = QtGui.QGridLayout(self.groupBox)
self.swapOptionsComboBoxView = QComboBox(self.groupBox)
self.gridLayout.addWidget(self.swapOptionsComboBoxView, 0, 0, 1, 2)
self.applyToAllCheckBox = QtGui.QCheckBox(tr("Apply to all accounts"))
self.gridLayout.addWidget(self.applyToAllCheckBox, 1, 0, 1, 1)
self.swapButton = QPushButton(tr("Fix"))
self.gridLayout.addWidget(self.swapButton, 1, 1, 1, 1)
self.targetAccountLayout.addWidget(self.groupBox)
self.verticalLayout.addLayout(self.targetAccountLayout)
self.tableView = TableView(self)
self.tableView.setEditTriggers(QtGui.QAbstractItemView.NoEditTriggers)
self.tableView.setDragEnabled(True)
self.tableView.setDragDropMode(QtGui.QAbstractItemView.InternalMove)
self.tableView.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection)
self.tableView.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows)
self.tableView.horizontalHeader().setHighlightSections(False)
self.tableView.horizontalHeader().setMinimumSectionSize(18)
self.tableView.verticalHeader().setVisible(False)
self.tableView.verticalHeader().setDefaultSectionSize(18)
self.verticalLayout.addWidget(self.tableView)
self.horizontalLayout = QtGui.QHBoxLayout()
spacerItem1 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
self.horizontalLayout.addItem(spacerItem1)
self.importButton = QPushButton(tr("Import"))
self.horizontalLayout.addWidget(self.importButton)
self.verticalLayout.addLayout(self.horizontalLayout)
self.tabView.setTabsClosable(True)
self.tabView.setDrawBase(False)
self.tabView.setDocumentMode(True)
self.tabView.setUsesScrollButtons(True)
def _setupColumns(self):
# Can't set widget alignment in a layout in the Designer
l = self.targetAccountLayout
l.setAlignment(self.targetAccountLabel, Qt.AlignTop)
l.setAlignment(self.targetAccountComboBox, Qt.AlignTop)
#--- Event Handlers
def currentTabChanged(self, index):
self.model.selected_pane_index = index
def importClicked(self):
self.model.import_selected_pane()
def swapClicked(self):
applyToAll = self.applyToAllCheckBox.isChecked()
self.model.perform_swap(applyToAll)
def tabCloseRequested(self, index):
self.model.close_pane(index)
self.tabView.removeTab(index)
def targetAccountChanged(self, index):
self.model.selected_target_account_index = index
self.table.updateColumnsVisibility()
#--- model --> view
def close(self):
self.hide()
def close_selected_tab(self):
self.tabView.removeTab(self.tabView.currentIndex())
def refresh_target_accounts(self):
# We disconnect the combobox because we don't want the clear() call to set the selected
# target index in the model.
self.targetAccountComboBox.currentIndexChanged.disconnect(self.targetAccountChanged)
self.targetAccountComboBox.clear()
self.targetAccountComboBox.addItems(self.model.target_account_names)
self.targetAccountComboBox.currentIndexChanged.connect(self.targetAccountChanged)
def refresh_tabs(self):
while self.tabView.count():
self.tabView.removeTab(0)
for pane in self.model.panes:
self.tabView.addTab(pane.name)
def set_swap_button_enabled(self, enabled):
self.swapButton.setEnabled(enabled)
def show(self):
# For non-modal dialogs, show() is not enough to bring the window at the forefront, we have
# to call raise() as well
QWidget.show(self)
self.raise_()
def update_selected_pane(self):
index = self.model.selected_pane_index
if index != self.tabView.currentIndex(): # this prevents infinite loops
self.tabView.setCurrentIndex(index)
self.targetAccountComboBox.setCurrentIndex(self.model.selected_target_account_index)
self.table.updateColumnsVisibility()
示例2: E4SideBar
# 需要导入模块: from PyQt4.QtGui import QTabBar [as 别名]
# 或者: from PyQt4.QtGui.QTabBar import addTab [as 别名]
#.........这里部分代码省略.........
def eventFilter(self, obj, evt):
"""
Protected method to handle some events for the tabbar.
@param obj reference to the object (QObject)
@param evt reference to the event object (QEvent)
@return flag indicating, if the event was handled (boolean)
"""
if obj == self.__tabBar:
if evt.type() == QEvent.MouseButtonPress:
pos = evt.pos()
for i in range(self.__tabBar.count()):
if self.__tabBar.tabRect(i).contains(pos):
break
if i == self.__tabBar.currentIndex():
if self.isMinimized():
self.expand()
else:
self.shrink()
return True
elif self.isMinimized():
self.expand()
elif evt.type() == QEvent.Wheel and not self.__stackedWidget.isHidden():
if evt.delta() > 0:
self.prevTab()
else:
self.nextTab()
return True
return QWidget.eventFilter(self, obj, evt)
def addTab(self, widget, iconOrLabel, label = None):
"""
Public method to add a tab to the sidebar.
@param widget reference to the widget to add (QWidget)
@param iconOrLabel reference to the icon or the labeltext of the tab
(QIcon, string or QString)
@param label the labeltext of the tab (string or QString) (only to be
used, if the second parameter is a QIcon)
"""
if label:
index = self.__tabBar.addTab(iconOrLabel, label)
self.__tabBar.setTabToolTip(index, label)
else:
index = self.__tabBar.addTab(iconOrLabel)
self.__tabBar.setTabToolTip(index, iconOrLabel)
self.__stackedWidget.addWidget(widget)
if self.__orientation in [E4SideBar.North, E4SideBar.South]:
self.__minSize = self.minimumSizeHint().height()
else:
self.__minSize = self.minimumSizeHint().width()
def insertTab(self, index, widget, iconOrLabel, label = None):
"""
Public method to insert a tab into the sidebar.
@param index the index to insert the tab at (integer)
@param widget reference to the widget to insert (QWidget)
@param iconOrLabel reference to the icon or the labeltext of the tab
(QIcon, string or QString)
@param label the labeltext of the tab (string or QString) (only to be
used, if the second parameter is a QIcon)
"""
示例3: MainWindow
# 需要导入模块: from PyQt4.QtGui import QTabBar [as 别名]
# 或者: from PyQt4.QtGui.QTabBar import addTab [as 别名]
#.........这里部分代码省略.........
button = self.columnsVisibilityButton
menu.popup(button.parentWidget().mapToGlobal(button.geometry().topLeft()))
def columnsMenuItemWasClicked(self):
action = self.sender()
if action is not None:
index = action.data()
self.model.toggle_column_menu_item(index)
def checkForUpdateTriggered(self):
QProcess.execute('updater.exe', ['/checknow'])
def aboutTriggered(self):
self.app.showAboutBox()
def openDebugLogTriggered(self):
debugLogPath = op.join(getAppData(), 'debug.log')
url = QUrl.fromLocalFile(debugLogPath)
QDesktopServices.openUrl(url)
#--- Other Signals
def currentTabChanged(self, index):
self.model.current_pane_index = index
self._setTabIndex(index)
def documentPathChanged(self):
if self.doc.documentPath:
title = "moneyGuru ({})".format(self.doc.documentPath)
else:
title = "moneyGuru"
self.setWindowTitle(title)
def tabCloseRequested(self, index):
self.model.close_pane(index)
def tabMoved(self, fromIndex, toIndex):
self.model.move_pane(fromIndex, toIndex)
#--- model --> view
def change_current_pane(self):
self._setTabIndex(self.model.current_pane_index)
def refresh_panes(self):
while self.tabBar.count() < self.model.pane_count:
self.tabBar.addTab('')
for i in range(self.model.pane_count):
pane_label = self.model.pane_label(i)
pane_label = escapeamp(pane_label)
self.tabBar.setTabText(i, pane_label)
pane_type = self.model.pane_type(i)
pane_view = self.model.pane_view(i)
# Ensure that the view's "view" has been created and bound
self._getViewforPane(pane_type, pane_view)
iconname = PANETYPE2ICON.get(pane_type)
icon = QIcon(QPixmap(':/{0}'.format(iconname))) if iconname else QIcon()
self.tabBar.setTabIcon(i, icon)
# It's important that we proceed with tab removal *after* we've completed tab initialization.
# We're walking on eggshells here. refresh_panes() can be called in multiple situations, one
# of them is during the opening of a document. When that happens when another document was
# previously opened, all views' model are uninitalized and don't have their "view" attribute
# set yet. If we proceed with the setCurrentIndex() call below before _getViewforPane()
# could be called above, we get a crash.
if self.tabBar.currentIndex() < self.model.pane_count:
# Normally, we don't touch the tabBar index here and wait for change_current_pane,
# but when we remove tabs, it's possible that currentTabChanged end up being called and
# then the tab selection is bugged. I tried disconnecting/reconnecting the signal, but
# this is buggy. So when a selected tab is about to be removed, we change the selection
# to the model's one immediately.
self.tabBar.setCurrentIndex(self.model.current_pane_index)
while self.tabBar.count() > self.model.pane_count:
self.tabBar.removeTab(self.tabBar.count()-1)
self.tabBar.setTabsClosable(self.model.pane_count > 1)
def refresh_status_line(self):
self.statusLabel.setText(self.model.status_line)
def refresh_undo_actions(self):
self._updateUndoActions()
def restore_window_frame(self, frame):
self.setGeometry(*frame)
def save_window_frame(self):
r = self.geometry()
return (r.x(), r.y(), r.width(), r.height())
def show_message(self, msg):
title = tr("Warning")
QMessageBox.warning(self, title, msg)
def update_area_visibility(self):
hidden = self.model.hidden_areas
graphimg = ':/graph_visibility_{}_16'.format('off' if PaneArea.BottomGraph in hidden else 'on')
pieimg = ':/piechart_visibility_{}_16'.format('off' if PaneArea.RightChart in hidden else 'on')
self.graphVisibilityButton.setIcon(QIcon(QPixmap(graphimg)))
self.piechartVisibilityButton.setIcon(QIcon(QPixmap(pieimg)))
def view_closed(self, index):
self.tabBar.removeTab(index)
self.tabBar.setTabsClosable(self.model.pane_count > 1)
示例4: SideBar
# 需要导入模块: from PyQt4.QtGui import QTabBar [as 别名]
# 或者: from PyQt4.QtGui.QTabBar import addTab [as 别名]
#.........这里部分代码省略.........
self.splitter.setSizes( sizes )
return
def isMinimized( self ):
""" Provides the minimized state """
return self.__minimized
def eventFilter( self, obj, evt ):
""" Handle click events for the tabbar """
if obj == self.__tabBar:
if evt.type() == QEvent.MouseButtonPress:
pos = evt.pos()
index = self.__tabBar.count() - 1
while index >= 0:
if self.__tabBar.tabRect( index ).contains( pos ):
break
index -= 1
if index == self.__tabBar.currentIndex():
if self.isMinimized():
self.expand()
else:
self.shrink()
return True
elif self.isMinimized():
if self.isTabEnabled( index ):
self.expand()
return QWidget.eventFilter( self, obj, evt )
def addTab( self, widget, iconOrLabel, label = None ):
""" Add a tab to the sidebar """
if label:
self.__tabBar.addTab( iconOrLabel, label )
else:
self.__tabBar.addTab( iconOrLabel )
self.__stackedWidget.addWidget( widget )
return
def insertTab( self, index, widget, iconOrLabel, label = None ):
""" Insert a tab into the sidebar """
if label:
self.__tabBar.insertTab( index, iconOrLabel, label )
else:
self.__tabBar.insertTab( index, iconOrLabel )
self.__stackedWidget.insertWidget( index, widget )
return
def removeTab( self, index ):
""" Remove a tab """
self.__stackedWidget.removeWidget( self.__stackedWidget.widget( index ) )
self.__tabBar.removeTab( index )
return
def clear( self ):
""" Remove all tabs """
while self.count() > 0:
self.removeTab( 0 )
return