本文整理汇总了Python中PyQt4.QtGui.QTabBar.currentIndex方法的典型用法代码示例。如果您正苦于以下问题:Python QTabBar.currentIndex方法的具体用法?Python QTabBar.currentIndex怎么用?Python QTabBar.currentIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtGui.QTabBar
的用法示例。
在下文中一共展示了QTabBar.currentIndex方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ImportWindow
# 需要导入模块: from PyQt4.QtGui import QTabBar [as 别名]
# 或者: from PyQt4.QtGui.QTabBar import currentIndex [as 别名]
class ImportWindow(QWidget):
def __init__(self, parent, doc):
QWidget.__init__(self, parent, Qt.Window)
self._setupUi()
self.doc = doc
self.model = ImportWindowModel(document=doc.model)
self.swapOptionsComboBox = ComboboxModel(model=self.model.swap_type_list, view=self.swapOptionsComboBoxView)
self.table = ImportTable(model=self.model.import_table, view=self.tableView)
self.model.view = self
self._setupColumns() # Can only be done after the model has been connected
self.tabView.tabCloseRequested.connect(self.tabCloseRequested)
self.tabView.currentChanged.connect(self.currentTabChanged)
self.targetAccountComboBox.currentIndexChanged.connect(self.targetAccountChanged)
self.importButton.clicked.connect(self.importClicked)
self.swapButton.clicked.connect(self.swapClicked)
def _setupUi(self):
self.setWindowTitle(tr("Import"))
self.resize(557, 407)
self.verticalLayout = QtGui.QVBoxLayout(self)
self.tabView = QTabBar(self)
self.tabView.setMinimumSize(QtCore.QSize(0, 20))
self.verticalLayout.addWidget(self.tabView)
self.targetAccountLayout = QtGui.QHBoxLayout()
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)
#.........这里部分代码省略.........
示例2: E4SideBar
# 需要导入模块: from PyQt4.QtGui import QTabBar [as 别名]
# 或者: from PyQt4.QtGui.QTabBar import currentIndex [as 别名]
#.........这里部分代码省略.........
self.__actionMethod = None
def isMinimized(self):
"""
Public method to check the minimized state.
@return flag indicating the minimized state (boolean)
"""
return self.__minimized
def isAutoHiding(self):
"""
Public method to check, if the auto hide function is active.
@return flag indicating the state of auto hiding (boolean)
"""
return self.__autoHide
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)
示例3: MainWindow
# 需要导入模块: from PyQt4.QtGui import QTabBar [as 别名]
# 或者: from PyQt4.QtGui.QTabBar import currentIndex [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 currentIndex [as 别名]
#.........这里部分代码省略.........
sizes[ selfIndex ] = self.__bigSize.height()
else:
self.setMinimumWidth( self.__minSize )
self.setMaximumWidth( self.__maxSize )
diff = self.__bigSize.width() - sizes[ selfIndex ]
sizes[ selfIndex ] = self.__bigSize.width()
if selfIndex == 0:
sizes[ 1 ] -= diff
else:
sizes[ selfIndex - 1 ] -= diff
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