<i id='9zvsR'><tr id='9zvsR'><dt id='9zvsR'><q id='9zvsR'><span id='9zvsR'><b id='9zvsR'><form id='9zvsR'><ins id='9zvsR'></ins><ul id='9zvsR'></ul><sub id='9zvsR'></sub></form><legend id='9zvsR'></legend><bdo id='9zvsR'><pre id='9zvsR'><center id='9zvsR'></center></pre></bdo></b><th id='9zvsR'></th></span></q></dt></tr></i><div id='9zvsR'><tfoot id='9zvsR'></tfoot><dl id='9zvsR'><fieldset id='9zvsR'></fieldset></dl></div>

      1. <small id='9zvsR'></small><noframes id='9zvsR'>

          <bdo id='9zvsR'></bdo><ul id='9zvsR'></ul>
        <tfoot id='9zvsR'></tfoot>
      2. <legend id='9zvsR'><style id='9zvsR'><dir id='9zvsR'><q id='9zvsR'></q></dir></style></legend>

        如何获取 QTableView 右键单击​​索引

        时间:2023-08-04

      3. <tfoot id='Plc44'></tfoot>
      4. <small id='Plc44'></small><noframes id='Plc44'>

            <bdo id='Plc44'></bdo><ul id='Plc44'></ul>

                  <tbody id='Plc44'></tbody>
                <i id='Plc44'><tr id='Plc44'><dt id='Plc44'><q id='Plc44'><span id='Plc44'><b id='Plc44'><form id='Plc44'><ins id='Plc44'></ins><ul id='Plc44'></ul><sub id='Plc44'></sub></form><legend id='Plc44'></legend><bdo id='Plc44'><pre id='Plc44'><center id='Plc44'></center></pre></bdo></b><th id='Plc44'></th></span></q></dt></tr></i><div id='Plc44'><tfoot id='Plc44'></tfoot><dl id='Plc44'><fieldset id='Plc44'></fieldset></dl></div>
                <legend id='Plc44'><style id='Plc44'><dir id='Plc44'><q id='Plc44'></q></dir></style></legend>

                • 本文介绍了如何获取 QTableView 右键单击​​索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  下面的代码创建了一个带有 QTableView 视图的对话框.左键单击 onLeftClick 函数会获得一个 QModelIndex index.此 QModelIndex 稍后用于打印左键单击单元格的行号和列号.

                  The code below creates a single dialog with a QTableView view. On left-click the onLeftClickfunction gets an QModelIndex index. This QModelIndex is used later to print the row and column numbers of the left-clicked cell.

                  如何获取被右键单击的单元格的QModelIndex索引?

                  How to get the QModelIndex index of the cell that was right-clicked?

                  from PyQt5.QtGui import *
                  from PyQt5.QtWidgets import *
                  from PyQt5.QtCore import *
                  app = QApplication([])
                  
                  
                  class Dialog(QDialog):
                      def __init__(self, parent=None):
                          super(Dialog, self).__init__(parent)
                          self.setLayout(QVBoxLayout())
                          self.view = QTableView(self)
                          self.view.setSelectionBehavior(QTableWidget.SelectRows)
                          self.view.setContextMenuPolicy(Qt.CustomContextMenu)
                          self.view.customContextMenuRequested.connect(self.onRightClick)
                          self.view.clicked.connect(self.onLeftClick)
                  
                          self.view.setModel(QStandardItemModel(4, 4))
                          for each in [(row, col, QStandardItem('item %s_%s' % (row, col))) for row in range(4) for col in range(4)]:
                              self.view.model().setItem(*each)
                  
                          self.layout().addWidget(self.view)
                          self.resize(500, 250)
                          self.show()
                  
                      def onRightClick(self, qPoint):
                          sender = self.sender()
                          for index in self.view.selectedIndexes():
                              print 'onRightClick selected index.row: %s, selected index.column: %s' % (index.row(), index.column())
                  
                      def onLeftClick(self, index):
                          print 'onClick index.row: %s, index.row: %s' % (index.row(), index.column())
                  
                  
                  dialog = Dialog()
                  app.exec_()
                  

                  推荐答案

                  你必须使用 QAbstractScrollArea (QTableViewindexAt() 方法代码>):

                  You have to use the indexAt() method of the QAbstractScrollArea (QTableView):

                  def onRightClick(self, qPoint):
                      index = self.view.indexAt(qPoint)
                      if index.isValid():
                          print('onClick index.row: %s, index.col: %s' % (index.row(), index.column()))
                  

                  这篇关于如何获取 QTableView 右键单击​​索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何从 qcombobox 获取 itemdata? 下一篇:通过信号调用函数将默认键控参数更改为“Fals

                  相关文章

                  最新文章

                • <small id='CFhBI'></small><noframes id='CFhBI'>

                    • <bdo id='CFhBI'></bdo><ul id='CFhBI'></ul>
                  1. <legend id='CFhBI'><style id='CFhBI'><dir id='CFhBI'><q id='CFhBI'></q></dir></style></legend>

                      <tfoot id='CFhBI'></tfoot>

                      <i id='CFhBI'><tr id='CFhBI'><dt id='CFhBI'><q id='CFhBI'><span id='CFhBI'><b id='CFhBI'><form id='CFhBI'><ins id='CFhBI'></ins><ul id='CFhBI'></ul><sub id='CFhBI'></sub></form><legend id='CFhBI'></legend><bdo id='CFhBI'><pre id='CFhBI'><center id='CFhBI'></center></pre></bdo></b><th id='CFhBI'></th></span></q></dt></tr></i><div id='CFhBI'><tfoot id='CFhBI'></tfoot><dl id='CFhBI'><fieldset id='CFhBI'></fieldset></dl></div>