【问题标题】:Information from QTableWidget Cell to QTextBrowser - PySide从 QTableWidget Cell 到 QTextBrowser 的信息 - PySide
【发布时间】:2014-07-31 14:19:54
【问题描述】:

我正在尝试创建一个非常简单的应用程序,一旦单击按钮,单元格中的信息就会显示在文本浏览器中,但我无法让它工作。我已经尝试了几种方法,例如复制和 setHtml,但它不会复制过来。

我正在使用 PySide,Python 2.7,并且我在 Qt 设计器中创建了这些信号

def get_cell_content(self):
    currentRow = self.tableWidget.currentRow()
    if currentRow > -1:
        text = (self.tableWidget.item(currentRow, 0).text(), )

    self.textBrowser.setHtml(text)

使其工作的按钮

    self.getText.clicked.connect(self.get_cell_content)

有谁知道我怎样才能做到这一点?目前它在 textBrowser 中显示行索引,但我希望它显示当前单元格。

【问题讨论】:

  • 一种方法:定义一个 SLOT handleCellDoubleClicked(int, int),从这个特定的单元格中检索内容。设置文本浏览器内容。
  • 在什么情况下不工作?

标签: python qt pyside


【解决方案1】:

为了显示当前单元格的文本,您还应该检索列的索引:

def get_cell_content(self):
    currentRow = self.tableWidget.currentRow()
    currentCol = self.tableWidget.currentColumn()
    if currentRow > -1:
        text = (self.tableWidget.item(currentRow, currentCol).text(), )

    self.textBrowser.setHtml(text)

【讨论】:

    【解决方案2】:

    几件事可能会有所帮助:

    text = self.tableWidget.item(currentRow, 0).text()
    # remove the extra ()s
    

    您确定要使用 textBrowser 而不是 textEdit 及其 setPlainText() 方法吗?文本浏览器通过链接提供导航,但会自动处理大量更新显示。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-13
      • 1970-01-01
      • 2015-11-09
      • 2011-02-11
      • 1970-01-01
      相关资源
      最近更新 更多