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


Python QTableView.rowHeight方法代码示例

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


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

示例1: ListView

# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import rowHeight [as 别名]

#.........这里部分代码省略.........
        :param modelIndex:
        '''
#         if modelIndex.column() == self.model.ColumnID.Color:
#             self._colorDialog.setBrushColor(self._table.model()[modelIndex.row()].brushColor())
#             self._colorDialog.setPmapColor (self._table.model()[modelIndex.row()].pmapColor())
#             self._colorDialog.exec_()
#             #print "brush color = {}".format(self._colorDialog.brushColor().name())
#             #print "pmap color  = {}".format(self._colorDialog.pmapColor().name())
#             self._table.model().setData(modelIndex, (self._colorDialog.brushColor(),
#                                               self._colorDialog.pmapColor ()))

    def rowMovedTest(self, logicalIndex, oldVisualIndex, newVisualIndex):
        logger.debug( "{} {} {}".format(logicalIndex, oldVisualIndex, newVisualIndex) )

    def _setListViewLook(self):
        table = self._table
        #table.setDragEnabled(True)
        table.setAcceptDrops(True)
        table.setFocusPolicy(Qt.NoFocus)
        table.setShowGrid(False)
        table.horizontalHeader().hide()
        table.verticalHeader().hide()
        #table.horizontalHeader().setSectionResizeMode(1, QHeaderView.Stretch)
        table.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeToContents)
        
        
        table.setSelectionMode(QAbstractItemView.SingleSelection)
        table.setSelectionBehavior(QAbstractItemView.SelectRows)
     
    def selectRow(self, *args, **kwargs):
        self._table.selectRow(*args, **kwargs)
        
    def _onRowsChanged(self, parent, start, end):
        model = self._table.model()
        if model and model.rowCount() > 0:
            self.setCurrentIndex(self.PAGE_LISTVIEW)
        else:
            self.setCurrentIndex(self.PAGE_EMPTY)
        if self.parent()!=None: self.parent().updateGeometry()

    def setModel(self, model):
        QTableView.setModel(self._table, model)
        self._table.setSelectionModel(model._selectionModel)
        
        if model.rowCount() > 0:
            self.setCurrentIndex(self.PAGE_LISTVIEW)
        else:
            self.setCurrentIndex(self.PAGE_EMPTY)

        model.rowsInserted.connect(self._onRowsChanged)
        model.rowsRemoved.connect(self._onRowsChanged)
        self.model=model
        
        self._setListViewLook()
        


    @property
    def allowDelete(self):
        return not self._table.isColumnHidden(self.model.ColumnID.Delete)

    @allowDelete.setter
    def allowDelete(self, allow):
        self._table.setColumnHidden(self.model.ColumnID.Delete, not allow)

    def minimumSizeHint(self):
        #http://www.qtcentre.org/threads/14764-QTableView-sizeHint%28%29-issues
        t = self._table
        vHeader = t.verticalHeader()
        hHeader = t.horizontalHeader()
        doubleFrame = 2 * t.frameWidth()
        w = hHeader.length() + vHeader.width() + doubleFrame;
     
        contentH = 0
        if self._table.model(): 
            for i in range(self._table.model().rowCount()):
                contentH += self._table.rowHeight(i)
        contentH = max(90, contentH) 
        
        h = hHeader.height() + contentH + doubleFrame;
        from PyQt5.QtCore import QSize
        return QSize(w,h)

    def sizeHint(self):
        return self.minimumSizeHint()
    
    def shrinkToMinimum(self):
        """
        shrink the view around the 
        labels which are currently there
        """
        t = self._table
        hHeader = t.horizontalHeader()
        doubleFrame = 2 * t.frameWidth()     
        contentH = 0
        if self._table.model(): 
            for i in range(self._table.model().rowCount()):
                contentH += self._table.rowHeight(i)
        h =  contentH+2
        self.setFixedHeight(h)
开发者ID:DerThorsten,项目名称:ilastik,代码行数:104,代码来源:listView.py


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