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


Python QListView.viewport方法代码示例

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


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

示例1: VariableComboBox

# 需要导入模块: from PyQt4.QtGui import QListView [as 别名]
# 或者: from PyQt4.QtGui.QListView import viewport [as 别名]
class VariableComboBox(QWidget):

    def __init__(self, id, text="Input data", default=[], model=None):
        QWidget.__init__(self)
        self.setToolTip("<p>Select input dataset</p>")
        self.id = id
        if model is None:
            self.model = TreeModel()
        else:
            self.model = model
        self.comboBox = QComboBox()
        self.treeView = QListView(self.comboBox)
        self.connect(self.comboBox, SIGNAL("currentIndexChanged(int)"), 
            self.changeSelectedText)
        self.proxyModel = SortFilterProxyModel()
        self.proxyModel.setDynamicSortFilter(True)
        self.proxyModel.setFilterKeyColumn(1)
        self.proxyModel.setSourceModel(self.model)
        regexp = QRegExp("|".join([r"%s" % i for i in default]))
        self.proxyModel.setFilterRegExp(regexp)
#        self.treeView.header().hide()
        self.currentText = QString()
        self.treeView.setModel(self.proxyModel)

        self.comboBox.setModel(self.proxyModel)
        self.comboBox.setView(self.treeView)
#        self.treeView.hideColumn(1)
#        self.treeView.hideColumn(2)
#        self.treeView.hideColumn(3)
        self.treeView.viewport().installEventFilter(self.comboBox)
        label = QLabel(text)
        hbox = HBoxLayout()
        hbox.addWidget(label)
        hbox.addWidget(self.comboBox)
        self.setLayout(hbox)
        self.changeSelectedText(None)

    def changeSelectedText(self, index):
        item = self.treeView.currentIndex()
        if not item.isValid():
            item = self.proxyModel.index(0,0, QModelIndex())
        tree = self.treeView.model().parentTree(item)
        self.currentText = tree

    def parameterValues(self):
        return {self.id:self.currentText}
开发者ID:karstenv,项目名称:manageR,代码行数:48,代码来源:plugins_dialog.py

示例2: SortedListWidget

# 需要导入模块: from PyQt4.QtGui import QListView [as 别名]
# 或者: from PyQt4.QtGui.QListView import viewport [as 别名]
class SortedListWidget(QWidget):
    sortingOrderChanged = Signal()

    class _MyItemDelegate(QStyledItemDelegate):

        def __init__(self, sortingModel, parent):
            QStyledItemDelegate.__init__(self, parent)
            self.sortingModel = sortingModel

        def sizeHint(self, option, index):
            size = QStyledItemDelegate.sizeHint(self, option, index)
            return QSize(size.width(), size.height() + 4)

        def createEditor(self, parent, option, index):
            cb = QComboBox(parent)
            cb.setModel(self.sortingModel)
            cb.showPopup()
            return cb

        def setEditorData(self, editor, index):
            pass  # TODO: sensible default

        def setModelData(self, editor, model, index):
            text = editor.currentText()
            model.setData(index, text)

    def __init__(self, *args):
        QWidget.__init__(self, *args)
        self.setContentsMargins(0, 0, 0, 0)
        gridLayout = QGridLayout()
        gridLayout.setContentsMargins(0, 0, 0, 0)
        gridLayout.setSpacing(1)

        model = QStandardItemModel(self)
        model.rowsInserted.connect(self.__changed)
        model.rowsRemoved.connect(self.__changed)
        model.dataChanged.connect(self.__changed)

        self._listView = QListView(self)
        self._listView.setModel(model)
#        self._listView.setDragEnabled(True)
        self._listView.setDropIndicatorShown(True)
        self._listView.setDragDropMode(QListView.InternalMove)
        self._listView.viewport().setAcceptDrops(True)
        self._listView.setMinimumHeight(100)

        gridLayout.addWidget(self._listView, 0, 0, 2, 2)

        vButtonLayout = QVBoxLayout()

        self._upAction = QAction(
            "\u2191", self, toolTip="Move up")

        self._upButton = QToolButton(self)
        self._upButton.setDefaultAction(self._upAction)
        self._upButton.setSizePolicy(
            QSizePolicy.Fixed, QSizePolicy.MinimumExpanding)

        self._downAction = QAction(
            "\u2193", self, toolTip="Move down")

        self._downButton = QToolButton(self)
        self._downButton.setDefaultAction(self._downAction)
        self._downButton.setSizePolicy(
            QSizePolicy.Fixed, QSizePolicy.MinimumExpanding)

        vButtonLayout.addWidget(self._upButton)
        vButtonLayout.addWidget(self._downButton)

        gridLayout.addLayout(vButtonLayout, 0, 2, 2, 1)

        hButtonLayout = QHBoxLayout()

        self._addAction = QAction("+", self)
        self._addButton = QToolButton(self)
        self._addButton.setDefaultAction(self._addAction)

        self._removeAction = QAction("-", self)
        self._removeButton = QToolButton(self)
        self._removeButton.setDefaultAction(self._removeAction)
        hButtonLayout.addWidget(self._addButton)
        hButtonLayout.addWidget(self._removeButton)
        hButtonLayout.addStretch(10)
        gridLayout.addLayout(hButtonLayout, 2, 0, 1, 2)

        self.setLayout(gridLayout)
        self._addAction.triggered.connect(self._onAddAction)
        self._removeAction.triggered.connect(self._onRemoveAction)
        self._upAction.triggered.connect(self._onUpAction)
        self._downAction.triggered.connect(self._onDownAction)

    def sizeHint(self):
        size = QWidget.sizeHint(self)
        return QSize(size.width(), 100)

    def _onAddAction(self):
        item = QStandardItem("")
        item.setFlags(item.flags() ^ Qt.ItemIsDropEnabled)
        self._listView.model().appendRow(item)
        self._listView.setCurrentIndex(item.index())
#.........这里部分代码省略.........
开发者ID:nagyistoce,项目名称:orange-bio,代码行数:103,代码来源:OWPIPAx.py

示例3: OWDataSort

# 需要导入模块: from PyQt4.QtGui import QListView [as 别名]
# 或者: from PyQt4.QtGui.QListView import viewport [as 别名]
class OWDataSort(OWWidget):
    contextHandlers = {
        "": DomainContextHandler(
            "", ["sortroles"]
        )
    }
    settingsList = ["autoCommit"]

    def __init__(self, parent=None, signalManger=None, title="Data Sort"):
        super(OWDataSort, self).__init__(parent, signalManger, title,
                                         wantMainArea=False)

        #: Mapping (feature.name, feature.var_type) to (sort_index, sort_order)
        #: where sirt index is the position of the feature in the sortByModel
        #: and sort_order the Qt.SortOrder flag
        self.sortroles = {}

        self.autoCommit = False
        self._outputChanged = False

        box = OWGUI.widgetBox(self.controlArea, "Sort By Features")
        self.sortByView = QListView()
        self.sortByView.setItemDelegate(SortParamDelegate(self))
        self.sortByView.setSelectionMode(QListView.ExtendedSelection)
        self.sortByView.setDragDropMode(QListView.DragDrop)
        self.sortByView.setDefaultDropAction(Qt.MoveAction)
        self.sortByView.viewport().setAcceptDrops(True)

        self.sortByModel = VariableListModel(
            flags=Qt.ItemIsEnabled | Qt.ItemIsSelectable |
                  Qt.ItemIsDragEnabled | Qt.ItemIsEditable
        )
        self.sortByView.setModel(self.sortByModel)

        box.layout().addWidget(self.sortByView)

        box = OWGUI.widgetBox(self.controlArea, "Unused Features")
        self.unusedView = QListView()
        self.unusedView.setSelectionMode(QListView.ExtendedSelection)
        self.unusedView.setDragDropMode(QListView.DragDrop)
        self.unusedView.setDefaultDropAction(Qt.MoveAction)
        self.unusedView.viewport().setAcceptDrops(True)

        self.unusedModel = VariableListModel(
            flags=Qt.ItemIsEnabled | Qt.ItemIsSelectable |
                  Qt.ItemIsDragEnabled
        )
        self.unusedView.setModel(self.unusedModel)

        box.layout().addWidget(self.unusedView)

        box = OWGUI.widgetBox(self.controlArea, "Output")
        cb = OWGUI.checkBox(box, self, "autoCommit", "Auto commit")
        b = OWGUI.button(box, self, "Commit", callback=self.commit)
        OWGUI.setStopper(self, b, cb, "_outputChanged", callback=self.commit)

    def setData(self, data):
        """
        Set the input data.
        """
        self._storeRoles()

        self.closeContext("")
        self.data = data

        if data is not None:
            self.openContext("", data)
            domain = data.domain
            features = (domain.variables + domain.class_vars +
                        domain.get_metas().values())
            sort_by = []
            unused = []

            for feat in features:
                hint = self.sortroles.get((feat.name, feat.var_type), None)
                if hint is not None:
                    index, order = hint
                    sort_by.append((feat, index, order))
                else:
                    unused.append(feat)

            sort_by = sorted(sort_by, key=itemgetter(1))
            self.sortByModel[:] = [feat for feat, _, _ in sort_by]
            self.unusedModel[:] = unused

            # Restore the sort orders
            for i, (_, _, order) in enumerate(sort_by):
                index = self.sortByModel.index(i, 0)
                self.sortByModel.setData(index, order, SortOrderRole)

        self.commit()

    def _invalidate(self):
        if self.autoCommit:
            self.commit()
        else:
            self._outputChanged = True

    def _sortingParams(self):
        params = []
#.........这里部分代码省略.........
开发者ID:AutumnLight,项目名称:orange,代码行数:103,代码来源:OWDataSort.py


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