Results 1 to 2 of 2

Thread: QSyntaxHighlighter for rows inside a table inside a QTextEdit

  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 21:43.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSyntaxHighlighter for rows inside a table inside a QTextEdit

    QSyntaxHighlighter is not meant to work with rich text. You have to do your own parsing and coloring by injecting QTextCharFormat objects directly into your document.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

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