Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Change already appended text of document in Textbrowser
Forum Updated to NodeBB v4.3 + New Features

Change already appended text of document in Textbrowser

Scheduled Pinned Locked Moved Unsolved Qt for Python
2 Posts 2 Posters 391 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    levoxtrip
    wrote on last edited by
    #1

    Hey everyone, I'm working with opencv object detection in pyqt5. Everytime something gets detected some text get's appended to a textlist which is displayed in a pyqt5 textbrowser.
    I want to hightlight only the last generated text and want to change the color of the before generated text.
    Has anyone an idea how to achieve that. How to change already appended text?
    Thanks in advance

    eyllanescE 1 Reply Last reply
    0
    • L levoxtrip

      Hey everyone, I'm working with opencv object detection in pyqt5. Everytime something gets detected some text get's appended to a textlist which is displayed in a pyqt5 textbrowser.
      I want to hightlight only the last generated text and want to change the color of the before generated text.
      Has anyone an idea how to achieve that. How to change already appended text?
      Thanks in advance

      eyllanescE Offline
      eyllanescE Offline
      eyllanesc
      wrote on last edited by eyllanesc
      #2

      @levoxtrip Let's assume that what you indicate has been implemented so that the last row is highlighted, so if a new row is added then the previous row that is highlighted should not be highlighted but the new row, am I correct?

      If so then you can use the following demo:

      from PyQt5.QtCore import QDateTime, QTimer
      from PyQt5.QtGui import QColor, QTextCursor, QTextFormat
      from PyQt5.QtWidgets import QApplication, QTextBrowser
      
      
      class TextBrowser(QTextBrowser):
          def __init__(self, parent=None):
              super().__init__(parent)
              self.textChanged.connect(self.handle_text_changed)
      
          def handle_text_changed(self):
              previous_cursor = self.textCursor()
              self.moveCursor(QTextCursor.End)
              extraSelections = []
              selection = QTextBrowser.ExtraSelection()
              lineColor = QColor("salmon")
              selection.format.setBackground(lineColor)
              selection.format.setProperty(QTextFormat.FullWidthSelection, True)
              selection.cursor = self.textCursor()
              selection.cursor.clearSelection()
              extraSelections.append(selection)
              self.setExtraSelections(extraSelections)
              self.setTextCursor(previous_cursor)
      
      
      if __name__ == "__main__":
          import sys
      
          app = QApplication(sys.argv)
      
          w = TextBrowser()
          w.resize(640, 480)
          w.show()
      
          def handle_timeout():
              w.append(QDateTime.currentDateTime().toString())
      
          timer = QTimer(interval=1000, timeout=handle_timeout)
          timer.start()
      
          sys.exit(app.exec_())
      

      If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

      1 Reply Last reply
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved