Results 1 to 2 of 2

Thread: QSyntaxHighlighter for rows inside a table inside a QTextEdit

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2017
    Posts
    11
    Qt products
    Qt5
    Platforms
    Windows

    Question QSyntaxHighlighter for rows inside a table inside a QTextEdit

    Hello guys, I fail to find how to make http://doc.qt.io/qt-4.8/QSyntaxHighlighter works in an HTML table inside a QtextEdit.

    I have something like this:

    jUkYQwSLSQenk3tZt9mtUg.png

    And I am wondering how to hightlight text in the middle column. Specifically rules like:

    Highlight the first letter if the text doesn't starts with an upper.
    Highlight the entire row if the text doesn't ends in the next symbols: ?!.

    I tried the next code for it (Not C++, it's PyQt5) and it got close to what I want to do, but it works for the entire document, doesn't differenciate the rows on the table.
    I'm lost on how to tell the program that it should only apply rules for an html Cell on the 2nd column of the table and not the first column.

    Qt Code:
    1. self.highlighter = Highlighter(self.my_lineedit.document())
    2.  
    3. class Highlighter(QSyntaxHighlighter):
    4. def __init__(self, parent):
    5. super(Highlighter, self).__init__(parent)
    6. self.sectionFormat = QTextCharFormat()
    7. self.sectionFormat.setForeground(Qt.blue)
    8.  
    9. def highlightBlock(self, text):
    10. if text.startswith('Test'):
    11. self.setFormat(0, len(text), self.sectionFormat)
    To copy to clipboard, switch view to plain text mode 

    Any suggestion is appreciated. Even if the suggestions are for C++ code, it will help me to understand how it works and I'll adapt it to python myself.

    Note: I am using python 3.6 + PyQt 5.10.1
    Last edited by Saelyth; 19th March 2018 at 20:43.

Similar Threads

  1. Table inside QTreeView?
    By Bobruisk in forum Qt Programming
    Replies: 0
    Last Post: 11th July 2013, 11:05
  2. Replies: 0
    Last Post: 16th July 2012, 09:56
  3. insert a table view inside a Qtextedit Qt4
    By DarkMan20050 in forum Newbie
    Replies: 1
    Last Post: 26th November 2011, 08:22
  4. load table inside constructor
    By sattu in forum Qt Programming
    Replies: 0
    Last Post: 10th January 2011, 10:09
  5. QTableView 2 rows inside every row
    By skuda in forum Qt Programming
    Replies: 3
    Last Post: 22nd April 2009, 09:23

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.