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


Python QTreeView.setModel方法代码示例

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


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

示例1: Navigation

# 需要导入模块: from PyQt5.Qt import QTreeView [as 别名]
# 或者: from PyQt5.Qt.QTreeView import setModel [as 别名]
class Navigation(QWidget):
    """a navigation widget, 
    displaying all known projects and samples
    """
    changed_projects = pyqtSignal(str, str)
    changed_allele = pyqtSignal(str, int, str)
    change_view = pyqtSignal(int)
    refresh = pyqtSignal(str)
    
    def __init__(self, log, settings):
        self.log = log
        self.settings = settings
        super().__init__()
        self.init_UI()
        self.create_model()
        self.tree.expand(self.open_node)
        self.tree.clicked.connect(self.onClicked)
        
        self.tree.setContextMenuPolicy(Qt.CustomContextMenu)
        self.tree.customContextMenuRequested.connect(self.open_menu)
        
    def init_UI(self):
        """creates the UI
        """
        self.log.debug("Setting up Navigation area UI...")
        self.tree = QTreeView()
        self.tree.doubleClicked.connect(self.onDoubleClick)
        self.grid = QGridLayout()
        self.setLayout(self.grid)
        self.header_lbl = QLabel("Projects and Samples:", self)
        self.header_lbl.setStyleSheet(general.label_style_2nd)
        self.grid.addWidget(self.header_lbl, 0,0)
        
        self.grid.addWidget(self.tree, 1, 0)
        header = self.tree.header()
        header.hide()
        self.log.debug("\t=> Done!")
        
    def create_model(self):
        """creates or recreates the model
        """
        self.log.debug("Updating Navigation area...")
        root_node = Node("All")
        openNode = Node("Open", root_node)
        closedNode = Node("Closed", root_node)
        project_nodes = {}
        
        query = """select distinct sample_id_int, projects.project_name, project_status, allele_status, allele_nr 
        from projects left join alleles
            on projects.project_name = alleles.project_name 
        order by project_status desc, projects.project_name desc, sample_id_int
        """
        q = QtSql.QSqlQuery()
        q.exec_(query)
        while q.next():
            sample = q.value(0)
            project = q.value(1)
            pstatus = q.value(2)
            astatus = q.value(3)
            nr = q.value(4)
            try:
                pnode = project_nodes[project]
            except KeyError:
                if pstatus == "Closed":
                    topnode = closedNode
                else:
                    topnode = openNode
                pnode = Node(project, topnode, "Project")
                project_nodes[project] = pnode
            if sample:
                if nr != 1:
                    sample = "{} ({})".format(sample, nr)
                Node(sample, pnode, "Sample", astatus)
        
        self.model = NavigationModel(root_node)
        self.tree.setModel(self.model)
        
        self.open_node = self.model.index(0, 0, QModelIndex())
        self.closed_node = self.model.index(1, 0, QModelIndex())
        self.root_node = self.open_node.parent()
        self.log.debug("\t=> Done!")
        
    @pyqtSlot(str, str)
    def expand_project(self, project, status = None):
        """expands the node of the given project, 
        returns its index and parent-node's index 
        """
        self.log.debug("Expanding project {} ({})...".format(project, status))
        if not status in (None, "Open", "Closed"):
            return None, None
        myindex = self.open_node
        myparent_node = self.open_node
        if status == "Open":
            self.log.debug("Open")
            parent_node = self.open_node
            self.tree.expand(parent_node)
            self.tree.collapse(self.closed_node)
        elif status == "Closed":
            self.log.debug("Closed")
            parent_node = self.closed_node
#.........这里部分代码省略.........
开发者ID:DKMS-LSL,项目名称:typeloader,代码行数:103,代码来源:GUI_navigation.py

示例2: ShortcutConfig

# 需要导入模块: from PyQt5.Qt import QTreeView [as 别名]
# 或者: from PyQt5.Qt.QTreeView import setModel [as 别名]
class ShortcutConfig(QWidget):  # {{{

    changed_signal = pyqtSignal()

    def __init__(self, parent=None):
        QWidget.__init__(self, parent)
        self._layout = l = QGridLayout()
        self.setLayout(self._layout)
        self.header = QLabel(_('Double click on any entry to change the'
            ' keyboard shortcuts associated with it'))
        l.addWidget(self.header, 0, 0, 1, 3)
        self.view = QTreeView(self)
        self.view.setAlternatingRowColors(True)
        self.view.setHeaderHidden(True)
        self.view.setAnimated(True)
        l.addWidget(self.view, 1, 0, 1, 3)
        self.delegate = Delegate()
        self.view.setItemDelegate(self.delegate)
        self.delegate.sizeHintChanged.connect(self.editor_opened,
                type=Qt.QueuedConnection)
        self.delegate.changed_signal.connect(self.changed_signal)
        self.search = SearchBox2(self)
        self.search.initialize('shortcuts_search_history',
                help_text=_('Search for a shortcut by name'))
        self.search.search.connect(self.find)
        l.addWidget(self.search, 2, 0, 1, 1)
        self.nb = QPushButton(QIcon(I('arrow-down.png')), _('&Next'), self)
        self.pb = QPushButton(QIcon(I('arrow-up.png')), _('&Previous'), self)
        self.nb.clicked.connect(self.find_next)
        self.pb.clicked.connect(self.find_previous)
        l.addWidget(self.nb, 2, 1, 1, 1)
        l.addWidget(self.pb, 2, 2, 1, 1)
        l.setColumnStretch(0, 100)

    def restore_defaults(self):
        self._model.restore_defaults()
        self.changed_signal.emit()

    def commit(self):
        if self.view.state() == self.view.EditingState:
            self.delegate.accept_changes()
        self._model.commit()

    def initialize(self, keyboard):
        self._model = ConfigModel(keyboard, parent=self)
        self.view.setModel(self._model)

    def editor_opened(self, index):
        self.view.scrollTo(index, self.view.EnsureVisible)

    @property
    def is_editing(self):
        return self.view.state() == self.view.EditingState

    def find(self, query):
        if not query:
            return
        try:
            idx = self._model.find(query)
        except ParseException:
            self.search.search_done(False)
            return
        self.search.search_done(True)
        if not idx.isValid():
            info_dialog(self, _('No matches'),
                    _('Could not find any shortcuts matching %s')%query,
                    show=True, show_copy_button=False)
            return
        self.highlight_index(idx)

    def highlight_index(self, idx):
        self.view.scrollTo(idx)
        self.view.selectionModel().select(idx,
                self.view.selectionModel().ClearAndSelect)
        self.view.setCurrentIndex(idx)
        self.view.setFocus(Qt.OtherFocusReason)

    def find_next(self, *args):
        idx = self.view.currentIndex()
        if not idx.isValid():
            idx = self._model.index(0, 0)
        idx = self._model.find_next(idx,
                unicode(self.search.currentText()))
        self.highlight_index(idx)

    def find_previous(self, *args):
        idx = self.view.currentIndex()
        if not idx.isValid():
            idx = self._model.index(0, 0)
        idx = self._model.find_next(idx,
            unicode(self.search.currentText()), backwards=True)
        self.highlight_index(idx)

    def highlight_group(self, group_name):
        idx = self.view.model().index_for_group(group_name)
        if idx is not None:
            self.view.expand(idx)
            self.view.scrollTo(idx, self.view.PositionAtTop)
            self.view.selectionModel().select(idx,
                    self.view.selectionModel().ClearAndSelect)
#.........这里部分代码省略.........
开发者ID:AtulKumar2,项目名称:calibre,代码行数:103,代码来源:keyboard.py

示例3: BookWarriorHomepage

# 需要导入模块: from PyQt5.Qt import QTreeView [as 别名]
# 或者: from PyQt5.Qt.QTreeView import setModel [as 别名]
class BookWarriorHomepage ( QWidget,Ui_BookWarriorHomepage):
    updateSelection = pyqtSignal()
    def __init__ (self,model,parent=None):
        super(BookWarriorHomepage,self).__init__(parent)
        self.setupUi(self)
        self.max_vignettes = 20
        self.nb_col = 0
        self.nb_row = 0
        self.vignettes_liste = []
        self.model = model
        self.settings = Config().instance.settings
        self.list_warrior = []  # utilise pour maj selection depuis warrrior layout
    def setLeftPage(self):

        self.treeView = QTreeView(self)
        self.treeView.setObjectName("treeView")
        self.left_page_Layout.addWidget(self.treeView)
        self.treeView.activated.connect(self.changeCurrentSet)
        self.tree_model = TreeModel(self.model)
        self.treeView.setModel(self.tree_model)
        self.treeView.setWindowTitle("Simple Tree Model")
        self.treeView.header().hide()
        self.treeView.setAlternatingRowColors(True)

#         i = 0
#         self.treeKingdom.setColumnCount(3)
#         for faction in self.model.factions.values() :
#             item_f = QTreeWidgetItem(self.treeKingdom)
#             #self.treeKingdom.insertTopLevelItem(i,item_f)
#             item_f.setText(i,faction.name)
#             i = i +1
#             for empire in faction.empires.values():
#                 item_e = QTreeWidgetItem()
#                 item_e.setText(i,empire.name)
#                 item_f.addChild(item_e)
#                 for kingdom in empire.kingdoms.values():
#                     item_k = QTreeWidgetItem()
#                     item_k.setText(i,kingdom.name)
#                     item_e.addChild(item_k)
#                     for groupe in kingdom.groupes.values():
#                         item_g = QTreeWidgetItem()
#                         item_g.setText(i,groupe.name)
#                         print ('groupe',groupe.name)
#                         item_k.addChild(item_g)
    
    def setRightContent (self, list_warrior):
        self.list_warrior = list_warrior
        for v in self.vignettes_liste : 
            v.setParent(None)
            self.gridLayout.removeWidget(v)
#         while self.gridLayout.takeAt(0) !=  None :
#             del self.gridLayout.takeAt(0).widget
#             item =  self.gridLayout.takeAt(0)
#             print ('ll')
#             del item
        self.nb_col = 0
        self.nb_row = 0
        self.vignettes_liste = []
        for i in range (min(len(list_warrior),self.max_vignettes)):
            self.addVignette(list_warrior[i],i)

    def updateContent(self):
        pass
        
    def addVignette (self,warrior,i):
        widget_vignette = QWidget(self.vignettes)        
        layout_one_vignette = QVBoxLayout(widget_vignette)
        layout_one_vignette.setSpacing(0)
        layout_one_vignette.setContentsMargins(0, 0, 0, 0)
        warrior_button = QPushButton(widget_vignette)
        # on met plus car dans le cas du signal clicked on enverra True ou False (0 ou 1)
        warrior_button.setObjectName(str(i+2))
        warrior_button.clicked.connect(self.parent().goWarriorPage)
        sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        warrior_button.setFixedSize(QtCore.QSize(100,120))
        warrior_button.setSizePolicy(sizePolicy)
        layout_one_vignette.addWidget(warrior_button)
        
        # label
        warrior_label = HerosLabel(warrior,widget_vignette)
        layout_one_vignette.addWidget(warrior_label)
        
        max_col  = 3
        groupe_name = warrior.groupe().name
        if warrior.masterGroupe() != None : 
            groupe_name = warrior.masterGroupe().name+"/"+groupe_name
        

        #path = os.path.join(Config().instance.path_to_pic(),faction_name,empire_name,kingdom_name,"Picture",groupe_name,warrior_name
        icon = QIcon(warrior.thumb)

        #print (basepath+"/"+faction_name+"/"+empire_name+"/"+kingdom_name+"/Picture/"+groupe_name+"/"+warrior.name+"/portrait_thumbnail.jpg")
        warrior_button.setIcon(icon)
        warrior_button.setIconSize(QtCore.QSize(100,120))

        if self.nb_col == 0:
            self.nb_row = self.nb_row + 1

#.........这里部分代码省略.........
开发者ID:cyril711,项目名称:git-MythicWar,代码行数:103,代码来源:book_warrior_homepage.py


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