本文整理汇总了Python中PyQt4.QtGui.QTabBar.setCurrentIndex方法的典型用法代码示例。如果您正苦于以下问题:Python QTabBar.setCurrentIndex方法的具体用法?Python QTabBar.setCurrentIndex怎么用?Python QTabBar.setCurrentIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtGui.QTabBar
的用法示例。
在下文中一共展示了QTabBar.setCurrentIndex方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ImportWindow
# 需要导入模块: from PyQt4.QtGui import QTabBar [as 别名]
# 或者: from PyQt4.QtGui.QTabBar import setCurrentIndex [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 setCurrentIndex [as 别名]
class E4SideBar(QWidget):
"""
Class implementing a sidebar with a widget area, that is hidden or shown, if the
current tab is clicked again.
"""
Version = 1
North = 0
East = 1
South = 2
West = 3
def __init__(self, orientation = None, delay = 200, parent = None):
"""
Constructor
@param orientation orientation of the sidebar widget (North, East, South, West)
@param delay value for the expand/shrink delay in milliseconds (integer)
@param parent parent widget (QWidget)
"""
QWidget.__init__(self, parent)
self.__tabBar = QTabBar()
self.__tabBar.setDrawBase(True)
self.__tabBar.setShape(QTabBar.RoundedNorth)
self.__tabBar.setUsesScrollButtons(True)
self.__tabBar.setDrawBase(False)
self.__stackedWidget = QStackedWidget(self)
self.__stackedWidget.setContentsMargins(0, 0, 0, 0)
self.__autoHideButton = QToolButton()
self.__autoHideButton.setCheckable(True)
self.__autoHideButton.setIcon(UI.PixmapCache.getIcon("autoHideOff.png"))
self.__autoHideButton.setChecked(True)
self.__autoHideButton.setToolTip(
self.trUtf8("Deselect to activate automatic collapsing"))
self.barLayout = QBoxLayout(QBoxLayout.LeftToRight)
self.barLayout.setMargin(0)
self.layout = QBoxLayout(QBoxLayout.TopToBottom)
self.layout.setMargin(0)
self.layout.setSpacing(0)
self.barLayout.addWidget(self.__autoHideButton)
self.barLayout.addWidget(self.__tabBar)
self.layout.addLayout(self.barLayout)
self.layout.addWidget(self.__stackedWidget)
self.setLayout(self.layout)
# initialize the delay timer
self.__actionMethod = None
self.__delayTimer = QTimer(self)
self.__delayTimer.setSingleShot(True)
self.__delayTimer.setInterval(delay)
self.connect(self.__delayTimer, SIGNAL("timeout()"), self.__delayedAction)
self.__minimized = False
self.__minSize = 0
self.__maxSize = 0
self.__bigSize = QSize()
self.splitter = None
self.splitterSizes = []
self.__hasFocus = False # flag storing if this widget or any child has the focus
self.__autoHide = False
self.__tabBar.installEventFilter(self)
self.__orientation = E4SideBar.North
if orientation is None:
orientation = E4SideBar.North
self.setOrientation(orientation)
self.connect(self.__tabBar, SIGNAL("currentChanged(int)"),
self.__stackedWidget, SLOT("setCurrentIndex(int)"))
self.connect(e4App(), SIGNAL("focusChanged(QWidget*, QWidget*)"),
self.__appFocusChanged)
self.connect(self.__autoHideButton, SIGNAL("toggled(bool)"),
self.__autoHideToggled)
def setSplitter(self, splitter):
"""
Public method to set the splitter managing the sidebar.
@param splitter reference to the splitter (QSplitter)
"""
self.splitter = splitter
self.connect(self.splitter, SIGNAL("splitterMoved(int, int)"),
self.__splitterMoved)
self.splitter.setChildrenCollapsible(False)
index = self.splitter.indexOf(self)
self.splitter.setCollapsible(index, False)
def __splitterMoved(self, pos, index):
"""
Private slot to react on splitter moves.
@param pos new position of the splitter handle (integer)
@param index index of the splitter handle (integer)
"""
if self.splitter:
self.splitterSizes = self.splitter.sizes()
#.........这里部分代码省略.........
示例3: MainWindow
# 需要导入模块: from PyQt4.QtGui import QTabBar [as 别名]
# 或者: from PyQt4.QtGui.QTabBar import setCurrentIndex [as 别名]
#.........这里部分代码省略.........
self._shortcutPrevTab.activated.connect(self.showPreviousViewTriggered)
#--- QWidget overrides
def closeEvent(self, event):
if self.doc.confirmDestructiveAction():
event.accept()
else:
event.ignore()
#--- Private
def _print(self):
dialog = QPrintDialog(self)
if dialog.exec_() != QPrintDialog.Accepted:
return
printer = dialog.printer()
currentView = self.mainView.currentWidget()
viewPrinter = ViewPrinter(printer, currentView)
currentView.fitViewsForPrint(viewPrinter)
viewPrinter.render()
def _getViewforPane(self, pane_type, pane_view):
if pane_view in self.model2view:
view = self.model2view[pane_view]
else:
view = PANETYPE2VIEWCLASS[pane_type](model=pane_view)
self.model2view[pane_view] = view
self.mainView.addWidget(view)
view.restoreSubviewsSize()
return view
def _setTabIndex(self, index):
if not self.tabBar.count():
return
self.tabBar.setCurrentIndex(index)
self._updateActionsState()
pane_type = self.model.pane_type(index)
pane_view = self.model.pane_view(index)
view = self._getViewforPane(pane_type, pane_view)
self.mainView.setCurrentWidget(view)
view.setFocus()
def _activeView(self):
paneIndex = self.model.current_pane_index
return self.model.pane_view(paneIndex)
def _updateActionsState(self):
# Updates enable/disable checked/unchecked state of all actions. These state can change
# under various conditions: main view change, date range type change and when reconciliation
# mode is toggled
# Determine what actions are enabled
view = self._activeView()
viewType = view.VIEW_TYPE
isSheet = viewType in {PaneType.NetWorth, PaneType.Profit}
isTransactionOrEntryTable = viewType in {PaneType.Transaction, PaneType.Account}
canToggleReconciliation = viewType == PaneType.Account and view.can_toggle_reconciliation_mode
newItemLabel = {
PaneType.NetWorth: tr("New Account"),
PaneType.Profit: tr("New Account"),
PaneType.Transaction: tr("New Transaction"),
PaneType.Account: tr("New Transaction"),
PaneType.Schedule: tr("New Schedule"),
PaneType.Budget: tr("New Budget"),
PaneType.GeneralLedger: tr("New Transaction"),
}.get(viewType, tr("New Item")) #XXX make "New Item" disabled
示例4: SideBar
# 需要导入模块: from PyQt4.QtGui import QTabBar [as 别名]
# 或者: from PyQt4.QtGui.QTabBar import setCurrentIndex [as 别名]
class SideBar( QWidget ):
""" Sidebar with a widget area which is hidden or shown.
On by clicking any tab, off by clicking the current tab.
"""
North = 0
East = 1
South = 2
West = 3
def __init__( self, orientation = 2, parent = None ):
QWidget.__init__( self, parent )
self.__tabBar = QTabBar()
self.__tabBar.setDrawBase( True )
self.__tabBar.setShape( QTabBar.RoundedNorth )
self.__tabBar.setFocusPolicy( Qt.NoFocus )
self.__tabBar.setUsesScrollButtons( True )
self.__tabBar.setElideMode( 1 )
self.__stackedWidget = QStackedWidget( self )
self.__stackedWidget.setContentsMargins( 0, 0, 0, 0 )
self.barLayout = QBoxLayout( QBoxLayout.LeftToRight )
self.barLayout.setMargin( 0 )
self.layout = QBoxLayout( QBoxLayout.TopToBottom )
self.layout.setMargin( 0 )
self.layout.setSpacing( 0 )
self.barLayout.addWidget( self.__tabBar )
self.layout.addLayout( self.barLayout )
self.layout.addWidget( self.__stackedWidget )
self.setLayout( self.layout )
self.__minimized = False
self.__minSize = 0
self.__maxSize = 0
self.__bigSize = QSize()
self.splitter = None
self.__tabBar.installEventFilter( self )
self.__orientation = orientation
self.setOrientation( orientation )
self.__tabBar.currentChanged.connect(
self.__stackedWidget.setCurrentIndex )
return
def setSplitter( self, splitter ):
""" Set the splitter managing the sidebar """
self.splitter = splitter
return
def __getIndex( self ):
" Provides the widget index in splitters "
if self.__orientation == SideBar.West:
return 0
if self.__orientation == SideBar.East:
return 2
if self.__orientation == SideBar.South:
return 1
return 0
def __getWidget( self ):
" Provides a reference to the widget "
return self.splitter.widget( self.__getIndex() )
def shrink( self ):
""" Shrink the sidebar """
if self.__minimized:
return
self.__minimized = True
self.__bigSize = self.size()
if self.__orientation in [ SideBar.North, SideBar.South ]:
self.__minSize = self.minimumHeight()
self.__maxSize = self.maximumHeight()
else:
self.__minSize = self.minimumWidth()
self.__maxSize = self.maximumWidth()
self.__stackedWidget.hide()
sizes = self.splitter.sizes()
selfIndex = self.__getIndex()
if self.__orientation in [ SideBar.North, SideBar.South ]:
newHeight = self.__tabBar.minimumSizeHint().height()
self.setFixedHeight( newHeight )
diff = sizes[ selfIndex ] - newHeight
sizes[ selfIndex ] = newHeight
else:
newWidth = self.__tabBar.minimumSizeHint().width()
self.setFixedWidth( newWidth )
diff = sizes[ selfIndex ] - newWidth
sizes[ selfIndex ] = newWidth
if selfIndex == 0:
sizes[ 1 ] += diff
#.........这里部分代码省略.........