当前位置: 首页>>代码示例>>Python>>正文


Python QListWidget.setCurrentItem方法代码示例

本文整理汇总了Python中PySide.QtGui.QListWidget.setCurrentItem方法的典型用法代码示例。如果您正苦于以下问题:Python QListWidget.setCurrentItem方法的具体用法?Python QListWidget.setCurrentItem怎么用?Python QListWidget.setCurrentItem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PySide.QtGui.QListWidget的用法示例。


在下文中一共展示了QListWidget.setCurrentItem方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: QtReducePreferencePane

# 需要导入模块: from PySide.QtGui import QListWidget [as 别名]
# 或者: from PySide.QtGui.QListWidget import setCurrentItem [as 别名]
class QtReducePreferencePane(QDialog):
    # QtReducePreferencePane are the dialog windows for setting preferences.
    # Instances are created via menu or keyboard shortcut in QtReduceMainWindow.

    def __init__(self, parent=None):
        super(QtReducePreferencePane, self).__init__(parent)

        self.__createContents()

        self.toolBar = QtReducePreferencesToolBar(self)
        self.worksheet = QtReducePreferencesWorksheet(self)
        self.computation = QtReducePreferencesComputation(self)

        self.pagesWidget = QStackedWidget()
        self.pagesWidget.addWidget(self.toolBar)
        self.pagesWidget.addWidget(self.worksheet)
        self.pagesWidget.addWidget(self.computation)

        self.pagesWidget.setCurrentIndex(
            self.contentsWidget.row(self.contentsWidget.currentItem()))

        closeButton = QPushButton(self.tr("Close"))
        closeButton.clicked.connect(self.close)

        horizontalLayout = QHBoxLayout()
        horizontalLayout.addWidget(self.contentsWidget)
        horizontalLayout.addWidget(self.pagesWidget)

        buttonsLayout = QHBoxLayout()
        buttonsLayout.addStretch(1)
        buttonsLayout.addWidget(closeButton)

        mainLayout = QVBoxLayout()
        mainLayout.addLayout(horizontalLayout)
        mainLayout.addLayout(buttonsLayout)

        self.setLayout(mainLayout)

        self.setWindowTitle(self.tr("QReduce Preferences"))

    def changePage(self,current,previous):
        if not current:
            current = previous
        QSettings().setValue("preferences/currentitem",current.text())
        self.pagesWidget.setCurrentIndex(self.contentsWidget.row(current))

    def __createContents(self):
        self.contentsWidget = QListWidget()
        self.contentsWidget.setViewMode(QListView.ListMode)
        self.contentsWidget.setMovement(QListView.Static)

        toolBar = QListWidgetItem(self.contentsWidget)
        toolBar.setText(self.tr("Toolbar"))
        toolBar.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled)

        worksheet = QListWidgetItem(self.contentsWidget)
        worksheet.setText(self.tr("Worksheet"))
        worksheet.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled)

        computation = QListWidgetItem(self.contentsWidget)
        computation.setText(self.tr("Computation"))
        computation.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled)

        currentItem = QSettings().value("preferences/currentitem",
                                        self.tr(QtReduceDefaults.CURRENTITEM))
        if currentItem == self.tr("Toolbar"):
            self.contentsWidget.setCurrentItem(toolBar)
        elif currentItem == self.tr("Worksheet"):
            self.contentsWidget.setCurrentItem(worksheet)
        elif currentItem == self.tr("Computation"):
            self.contentsWidget.setCurrentItem(computation)

        self.contentsWidget.currentItemChanged.connect(self.changePage)
开发者ID:webushka,项目名称:reduce,代码行数:75,代码来源:qrpreferences.py

示例2: ConfigEditor

# 需要导入模块: from PySide.QtGui import QListWidget [as 别名]
# 或者: from PySide.QtGui.QListWidget import setCurrentItem [as 别名]

#.........这里部分代码省略.........
            settings_scroller = QScrollArea()
            settings_scroller.setWidget(settings)
            settings_scroller.setWidgetResizable(True)
            self.settings.addWidget(settings_scroller)
            
        font = self.categories.font()
        fm = QFontMetrics(font)
        self.categories.setMaximumWidth(fm.widthChar('X')*(longest_cat+4))
        
        self.main = QWidget()
        self.main_layout = QVBoxLayout()
        
        self.config_layout = QHBoxLayout()
        self.config_layout.addWidget(self.categories)
        self.config_layout.addWidget(self.settings)
        
        self.mainButtons = QDialogButtonBox(QDialogButtonBox.RestoreDefaults | QDialogButtonBox.Reset | QDialogButtonBox.Apply)
        self.main_apply = self.mainButtons.button(QDialogButtonBox.StandardButton.Apply)
        self.main_reset = self.mainButtons.button(QDialogButtonBox.StandardButton.Reset)
        self.main_defaults = self.mainButtons.button(QDialogButtonBox.StandardButton.LastButton)
        QObject.connect(self.mainButtons, SIGNAL('clicked(QAbstractButton *)'), self.mainbutton_clicked)
        
        self.dirty_check()
        
        self.main_layout.addLayout(self.config_layout)
        self.main_layout.addWidget(self.mainButtons)
        
        self.main.setLayout(self.main_layout)
        
        self.setCentralWidget(self.main)
        self.setWindowTitle(self.title)
        self.setUnifiedTitleAndToolBarOnMac(True)
        
        self.categories.setCurrentItem(self.categories.item(0))
        
        self.menuBar = QMenuBar()
        self.filemenu = QMenu('&File')
        self.quitAction = QAction(self)
        self.quitAction.setText('&Quit')
        if platform.system() != 'Darwin':
            self.quitAction.setShortcut(QKeySequence(Qt.CTRL + Qt.Key_Q))
        QObject.connect(self.quitAction, SIGNAL('triggered()'), self.quitApp)
        self.filemenu.addAction(self.quitAction)
        self.menuBar.addMenu(self.filemenu)
        self.setMenuBar(self.menuBar)
        
        self.show()
        self.activateWindow()
        self.raise_()
        
        self.setMinimumWidth(self.geometry().width()*1.2)
        
        screen = QDesktopWidget().screenGeometry()
        size = self.geometry()
        self.move((screen.width()-size.width())/2, (screen.height()-size.height())/2)
        
    def category_selected(self):
        self.settings.setCurrentIndex(self.config.config.index(self.categories.selectedItems()[0].text()))
        
    def mainbutton_clicked(self, button):
        if button == self.main_reset:
            for cat in self.base_cfg.get_categories():
                for setting in self.base_cfg.get_settings(cat):
                    self.widget_list[cat][setting].updateValue(self.base_cfg.get_setting(cat,setting))
        elif button == self.main_defaults:
            for cat in self.def_cfg.get_categories():
开发者ID:RyanHope,项目名称:jsonConfig,代码行数:70,代码来源:editor.py

示例3: MainControl

# 需要导入模块: from PySide.QtGui import QListWidget [as 别名]
# 或者: from PySide.QtGui.QListWidget import setCurrentItem [as 别名]
class MainControl(QWidget):

    toChangeChunk = Signal(tuple)
    toChangeSlice = Signal(int)

    def __init__(self, parent):
        super(MainControl, self).__init__(parent)
        self.parent = parent
        self.selectedMinerals = parent.selectedMinerals
        self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
        lb0 = QLabel('Minecraft Prism chunk minerals finder')
        lb1 = QLabel('Chunk X')
        lb2 = QLabel('Chunk Z')
        lb3 = QLabel('Show deposits of:')
        lb4 = QLabel('Slice Elevation')
        #lb0.setFrameStyle(QFrame.Box)
        lb0.setAlignment(Qt.AlignVCenter | Qt.AlignCenter)
        lb2.setAlignment(Qt.AlignVCenter | Qt.AlignRight)

        self.txtChunkX = QLineEdit()
        self.txtChunkZ = QLineEdit()
        self.txtElevation = QLineEdit(str(self.parent.presenter.elevation))
        self.txtChunkX.setAlignment(Qt.AlignVCenter | Qt.AlignCenter)
        self.txtChunkZ.setAlignment(Qt.AlignVCenter | Qt.AlignCenter)
        self.txtElevation.setAlignment(Qt.AlignVCenter | Qt.AlignCenter)

        self.btnViewChunk = QPushButton('View Chunk')
        self.btnViewChunk.clicked.connect(self.btnViewChunk_OnClick)
        
        self.btnSliceUp = QPushButton('Slice Up')
        self.btnSliceUp.clicked.connect(self.btnSliceUp_OnClick)
        self.btnSliceDown = QPushButton('Slice Down')
        self.btnSliceDown.clicked.connect(self.btnSliceDown_OnClick)
        
        self.lstMinerals = QListWidget()
        self.lstMinerals.setSelectionMode(QAbstractItemView.ExtendedSelection)
        self.lstMinerals.addItem(SelectedMineral('Gold', 14))
        self.lstMinerals.addItem(SelectedMineral('Iron', 15))
        self.lstMinerals.addItem(SelectedMineral('Diamond', 56))
        self.lstMinerals.addItem(SelectedMineral('Redstone', 73))
        self.lstMinerals.addItem(SelectedMineral('Obsidian', 49))
        self.lstMinerals.addItem(SelectedMineral('Coal', 16))
        self.lstMinerals.addItem(SelectedMineral('Lazurit', 21))
        self.lstMinerals.setCurrentItem(self.lstMinerals.item(0))
        self.lstMinerals.itemSelectionChanged.connect(self.onSelectedMinerals)

        elevBox = QHBoxLayout()
        elevBox.addWidget(lb4)
        elevBox.addWidget(self.txtElevation)
        elevBox.addWidget(self.btnSliceUp)
        elevBox.addWidget(self.btnSliceDown)
        
        ly = QGridLayout()
        ly.addWidget(lb0,               0, 0, 1, 4)
        ly.addWidget(lb1,               1, 0, 1, 1)
        ly.addWidget(self.txtChunkX,    1, 1, 1, 1)
        ly.addWidget(lb2,               1, 2, 1, 1)
        ly.addWidget(self.txtChunkZ,    1, 3, 1, 1)
        ly.addWidget(lb3,               2, 0, 1, 2)
        ly.addWidget(self.lstMinerals,  2, 2, 1, 2)
        ly.addWidget(self.btnViewChunk, 3, 1, 1, 2)
        ly.addLayout(elevBox,           4, 0, 1, 4)
        ly.setColumnStretch(0, 20)
        ly.setColumnStretch(1, 15)
        ly.setColumnStretch(2, 46)
        ly.setColumnStretch(3, 19)

        self.setLayout(ly)

    def sizeHint(self):
        return QSize(self.parent.controlsWidth, 180)

    def btnViewChunk_OnClick(self):
        chX = int(self.txtChunkX.text())
        chZ = int(self.txtChunkZ.text())
        self.toChangeChunk.emit((chX, chZ))

    def btnSliceUp_OnClick(self):
        elev = int(self.txtElevation.text()) + 1
        if elev < 64:
            self.toChangeSlice.emit(elev)
            self.txtElevation.setText(str(elev))

    def btnSliceDown_OnClick(self):
        elev = int(self.txtElevation.text()) - 1
        if elev > -1:
            self.toChangeSlice.emit(elev)
            self.txtElevation.setText(str(elev))

    def onSelectedMinerals(self):
        selMin = []
        for item in self.lstMinerals.selectedItems():
            selMin.append(item.blockCode)
        self.parent.selectedMinerals.setSelectedMinerals(selMin)
开发者ID:ydanilin,项目名称:MinecraftMinerals,代码行数:96,代码来源:mcw.py


注:本文中的PySide.QtGui.QListWidget.setCurrentItem方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。