栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Python QAbstractItemModel.createIndex方法代码示例

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Python QAbstractItemModel.createIndex方法代码示例

Python QStringListModel.createIndex方法代码示例

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

示例1: OrderItemsDialog
# 需要导入模块: from PyQt5.QtCore import QStringListModel [as 别名]
# 或者: from PyQt5.QtCore.QStringListModel import createIndex [as 别名]
class OrderItemsDialog(QDialog, Ui_OrderItemsDialog):
    """
    This class is a dialog for changing the order of qualitative parameter's values

    The dialog lists the values and allow changing the order using Up and Down buttons
    which replace the selected value with the one before/after it in the list
    """

    def __init__(self, parent, listToOrder: list):
        """
        Initialize the change order dialog

        Args:
            parent : (QDialog) - The parent dialog
            listToOrder : (list) - The list to set the order for
        """
        QDialog.__init__(self, parent)
        self.setupUi(self)
        self.listToOrder = listToOrder
        self.model = QStringListModel(self)
        self.model.setStringList(listToOrder)
        self.listView_items.setModel(self.model)
        self.pushButton_up.clicked.connect(self.pushButton_up_clicked)
        self.pushButton_down.clicked.connect(self.pushButton_down_clicked)

    def pushButton_up_clicked(self):
        """
        Replace the selected item with the one before it
        """
        selectedIndex = self.listView_items.currentIndex().row()
        self.replaceItems(selectedIndex, selectedIndex - 1)

    def pushButton_down_clicked(self):
        """
        Replace the selected item with the one after it
        """
        selectedIndex = self.listView_items.currentIndex().row()
        self.replaceItems(selectedIndex, selectedIndex + 1)

    def replaceItems(self, fromIndex, toIndex):
        """
        Replace 2 items

        Args:
            fromIndex   : (int) - the index of the selected item
            toIndex     : (int) - the target index of the selected item
        """
        if toIndex in range(len(self.listToOrder)):
            temp = self.listToOrder[toIndex]
            self.listToOrder[toIndex] = self.listToOrder[fromIndex]
            self.listToOrder[fromIndex] = temp
            self.model.setStringList(self.listToOrder)
            self.model.dataChanged.emit(
                self.listView_items.indexAt(QPoint(0, 0)),
                self.listView_items.indexAt(QPoint(len(self.listToOrder), 0)))
            index = self.model.createIndex(toIndex, 0)  # 创建index
            self.listView_items.setCurrentIndex(index)
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1009402.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号