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


Python QTableView.setItemDelegateForColumn方法代码示例

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


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

示例1: _makeTable

# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import setItemDelegateForColumn [as 别名]
    def _makeTable(self, model):
        table = QTableView(self)
        table.setModel(model)
        table.hideColumn(0)
        table.setShowGrid(False)

        subListDelegate = SubListItemDelegate()
        table.setItemDelegateForColumn(1, subListDelegate)
        table.setItemDelegateForColumn(2, subListDelegate)
        table.horizontalHeader().setSectionResizeMode(3, QHeaderView.Stretch)
        table.horizontalHeader().setSectionResizeMode(4, QHeaderView.ResizeToContents)
        return table
开发者ID:mgoral,项目名称:subconvert,代码行数:14,代码来源:Synchronizer.py

示例2: initUI

# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import setItemDelegateForColumn [as 别名]
    def initUI(self):

        Model=QStandardItemModel()
        Model.setColumnCount(3)
        Model.setHorizontalHeaderLabels(["clmn1","clmn2","clmn3"])
        Model.appendRow([QStandardItem(11),QStandardItem(12),QStandardItem(13)])
        Model.appendRow([QStandardItem(21),QStandardItem(22),QStandardItem(23)])

        Table=QTableView(self)
        Table.setModel(Model)
        ButDeleg=ButtonDelegate(Table)
        Table.setItemDelegateForColumn(1,ButDeleg)
        TXTDelegate=PlainTextEditDelegate()
        Table.setItemDelegateForColumn(0,TXTDelegate)
        ButDeleg.clicked.connect(self.Prnt)

        mainLayout = QVBoxLayout()
        mainLayout.setContentsMargins(0,0,0,0)
        mainLayout.addWidget(Table)
        self.setLayout(mainLayout)
开发者ID:tyrbonit,项目名称:WordPackReplacer,代码行数:22,代码来源:Delegates.py

示例3: initUI

# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import setItemDelegateForColumn [as 别名]
    def initUI(self):
        #ReplaceModel
        ReplaceModel=QStandardItemModel()
        ReplaceModel.setColumnCount(3)
        ReplaceModel.setHorizontalHeaderLabels(["Найти","Заменить на","Настройки"])
        #/ReplaceModel

        #replaceTable
        replaceTable = QTableView(self)
        #replaceTable.setToolTip("Таблица поиска и замены,\nдобавьте строку и заполните текст для поиска и замены,\nвы также можете выбрать индивидуальные опции поиска для данной строки")
        #replaceTable.horizontalHeader().setToolTip("Найти - Текст для поиска\nЗаменить - Текст замены\nЗн. - Подстановочные знаки\nЦв. - Выделение цветом\nЖ - Выделение жирным шрифтом\nН - Изменять надписи\nWA - Изменять объкты WordArt")
        replaceTable.setModel(ReplaceModel)
        replaceTable.horizontalHeader().setSectionResizeMode(1, QHeaderView.Stretch)
        replaceTable.horizontalHeader().setSectionResizeMode(2, QHeaderView.ResizeToContents)
        replaceTable.horizontalHeader().setSectionResizeMode(3, QHeaderView.ResizeToContents)
        """replaceTable.horizontalHeader().setSectionResizeMode(4, QHeaderView.ResizeToContents)
        replaceTable.horizontalHeader().setSectionResizeMode(5, QHeaderView.ResizeToContents)
        replaceTable.horizontalHeader().setSectionResizeMode(6, QHeaderView.ResizeToContents)"""
        replaceTable.horizontalHeader().resizeSection(0,500)
        replaceTable.setItemDelegateForColumn(0,PlainTextEditDelegate(replaceTable))
        replaceTable.setItemDelegateForColumn(1,PlainTextEditDelegate(replaceTable))

        #btnDeleg=ButtonDelegate(replaceTable)
        #btnDeleg.clicked.connect(self.setItemOpt)
        #replaceTable.clicked.connect(self.setItemOpt)

        #replaceTable.setItemDelegateForColumn(2,btnDeleg)
        #replaceTable.setItemDelegateForColumn(6,CheckBoxDelegate(replaceTable))
        #/replaceTable

        #buttonBox
        sklonPadejBtn=QPushButton("Просклонять")
        addRowBtn=QPushButton("Добавить строку")
        delRowBtn=QPushButton("Удалить строку")
        clearTable=QPushButton("Очистить")
        buttonBox = QDialogButtonBox(Qt.Horizontal)
        buttonBox.addButton(sklonPadejBtn, QDialogButtonBox.ActionRole)
        buttonBox.addButton(addRowBtn, QDialogButtonBox.ActionRole)
        buttonBox.addButton(delRowBtn, QDialogButtonBox.ActionRole)
        buttonBox.addButton(clearTable, QDialogButtonBox.ActionRole)
        #/buttonBox

        #mainLayout
        mainLayout = QVBoxLayout()
        mainLayout.setContentsMargins(0,0,0,0)

        self.optionWdgt=Options()
        mainLayout.setMenuBar(self.optionWdgt)

        mainLayout.addWidget(replaceTable)
        mainLayout.addWidget(buttonBox)
        #/mainLayout

        #self
        self.setLayout(mainLayout)
        self.ReplaceModel=ReplaceModel
        self.replaceTable=replaceTable
        #/self

        #connections
        sklonPadejBtn.clicked.connect(self.addSklonenie)
        addRowBtn.clicked.connect(self.addRow)
        delRowBtn.clicked.connect(self.delRow)
        clearTable.clicked.connect(self.clearReplaceTable)
        ReplaceModel.itemChanged.connect(self.ChangeReplaceList)
开发者ID:tyrbonit,项目名称:WordPackReplacer,代码行数:67,代码来源:ReplaceTableWidget.py

示例4: SubtitleEditor

# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import setItemDelegateForColumn [as 别名]
class SubtitleEditor(SubTab):
    def __init__(self, filePath, subtitleData, parent = None):
        name = os.path.split(filePath)[1]
        super(SubtitleEditor, self).__init__(name, parent)
        self.__initWidgets()
        self.__initContextMenu()

        self._settings = SubSettings()

        self._filePath = filePath
        self._movieFilePath = None
        self._subtitleData = subtitleData

        self.refreshSubtitles()

        # Some signals
        self._subtitleData.fileChanged.connect(self.fileChanged)
        self._subtitleData.subtitlesAdded.connect(self._subtitlesAdded)
        self._subtitleData.subtitlesRemoved.connect(self._subtitlesRemoved)
        self._subtitleData.subtitlesChanged.connect(self._subtitlesChanged)
        self._model.itemChanged.connect(self._subtitleEdited)
        self.customContextMenuRequested.connect(self.showContextMenu)

    def __initWidgets(self):
        minimalSizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)

        # List of subtitles
        subListDelegate = SubListItemDelegate()
        self._model = QStandardItemModel(0, 3, self)
        self._model.setHorizontalHeaderLabels([_("Begin"), _("End"), _("Subtitle")])
        self._subList = QTableView(self)
        self._subList.setModel(self._model)
        self._subList.setItemDelegateForColumn(0, subListDelegate)
        self._subList.setItemDelegateForColumn(1, subListDelegate)
        self._subList.horizontalHeader().setSectionResizeMode(2, QHeaderView.Stretch)

        self._searchBar = SearchBar(self)
        self._searchBar.hide()

        # Top toolbar
        toolbar = QHBoxLayout()
        toolbar.setAlignment(Qt.AlignLeft)
        #toolbar.addWidget(someWidget....)
        toolbar.addStretch(1)

        # Main layout
        grid = QGridLayout()
        grid.setSpacing(10)
        grid.setContentsMargins(0, 3, 0, 0)
        grid.addLayout(toolbar, 0, 0, 1, 1) # stretch to the right
        grid.addWidget(self._subList, 1, 0)
        grid.addWidget(self._searchBar, 2, 0)
        self.setLayout(grid)

    def __initContextMenu(self):
        self._contextMenu = QMenu(self)
        self.setContextMenuPolicy(Qt.CustomContextMenu)
        af = ActionFactory(self)

        insertSub = af.create(title = _("&Insert subtitle"), icon = "list-add",
            connection = self.insertNewSubtitle)
        self._contextMenu.addAction(insertSub)

        insertSub = af.create(title = _("&Add subtitle"), icon = "list-add",
            connection = self.addNewSubtitle)
        self._contextMenu.addAction(insertSub)

        removeSub = af.create(title = _("&Remove subtitles"), icon = "list-remove",
            connection = self.removeSelectedSubtitles)
        self._contextMenu.addAction(removeSub)

    def _changeRowBackground(self, rowNo, bg):
        with DisableSignalling(self._model.itemChanged, self._subtitleEdited):
            for columnNo in range(self._model.columnCount()):
                item = self._model.item(rowNo, columnNo)
                item.setBackground(bg)

    def _changeItemData(self, item, val, role):
        with DisableSignalling(self._model.itemChanged, self._subtitleEdited):
            item.setData(val, role)

    def _handleIncorrectItem(self, item):
        with DisableSignalling(self._model.itemChanged, self._subtitleEdited):
            item.setData(False, CustomDataRoles.ErrorFlagRole)

        bg = item.background()
        rowNo = item.row()
        self._changeRowBackground(rowNo, Qt.red)
        QTimer.singleShot(600, lambda rowNo=rowNo, bg=bg: self._changeRowBackground(rowNo, bg))

    def _subtitleEdited(self, item):
        modelIndex = item.index()
        column = modelIndex.column()
        subNo = modelIndex.row()

        errorFlag = item.data(CustomDataRoles.ErrorFlagRole)
        if errorFlag is True:
            self._handleIncorrectItem(item)
        else:
            # TODO: timeStart and timeEnd might be displayed in a frame format in a bright future.
#.........这里部分代码省略.........
开发者ID:mgoral,项目名称:subconvert,代码行数:103,代码来源:SubtitleTabs.py


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