Example #1
0
class SelectICDialog:
    def __init__(self, ic_list):
        ic_list.sort()

        self.__ic_model = QStringListModel(ic_list)
        self.__accepted = False
        self.__selectedIC = None

    def buildGUI(self):
        ui_file_loader = QUiLoader()
        dialog_ui_file = QFile("ui/select_ic.ui")
        dialog_ui_file.open(QFile.ReadOnly)
        self._window = ui_file_loader.load(dialog_ui_file)
        dialog_ui_file.close()

        self.__lv = self._window.findChild(QListView, "listView")
        self.__lv.setModel(self.__ic_model)
        self.__lv.activated.connect(self.onActivated)
        self._window.accepted.connect(self.onAccepted)

    def getResult(self):
        return self.__accepted, self.__selectedIC

    def show(self):
        self._window.exec_()

    @Slot()
    def onActivated(self, idx):
        self._window.accept()

    @Slot()
    def onAccepted(self):
        idx_list = self.__lv.selectedIndexes()
        if len(idx_list) == 1:
            self.__accepted = True
            self.__selectedIC = self.__ic_model.data(idx_list[0])
Example #2
0
##
## $QT_BEGIN_LICENSE:GPL-EXCEPT$
## Commercial License Usage
## Licensees holding valid commercial Qt licenses may use this file in
## accordance with the commercial license agreement provided with the
## Software or, alternatively, in accordance with the terms contained in
## a written agreement between you and The Qt Company. For licensing terms
## and conditions see https://www.qt.io/terms-conditions. For further
## information use the contact form at https://www.qt.io/contact-us.
##
## GNU General Public License Usage
## Alternatively, this file may be used under the terms of the GNU
## General Public License version 3 as published by the Free Software
## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
## included in the packaging of this file. Please review the following
## information to ensure the GNU General Public License requirements will
## be met: https://www.gnu.org/licenses/gpl-3.0.html.
##
## $QT_END_LICENSE$
##
#############################################################################

from PySide2.QtCore import Qt, QPersistentModelIndex, QStringListModel

if __name__ == '__main__':
    stringListModel = QStringListModel(['one', 'two'])
    idx = stringListModel.index(1, 0)
    persistentModelIndex = QPersistentModelIndex(idx)
    stringListModel.data(persistentModelIndex, Qt.DisplayRole)