Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to read syntax highlighting data from QTextDocument?
Forum Updated to NodeBB v4.3 + New Features

How to read syntax highlighting data from QTextDocument?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 217 Views 1 Watching
  • 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.
  • A Offline
    A Offline
    AndrzejB
    wrote on last edited by
    #1

    My simple test program

    MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent)
    {
        QPlainTextEdit *edit = new QPlainTextEdit(this);
        KSyntaxHighlighting::SyntaxHighlighter *highlighter;
        auto doc = edit->document();
        highlighter = new KSyntaxHighlighting::SyntaxHighlighter(doc);
        const auto def = repository.definitionForName("C++");
        highlighter->setDefinition(def);
        const auto theme = repository.theme("Breeze Light");
        highlighter->setTheme(theme);
        highlighter->rehighlight();
        edit->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont));
        setCentralWidget(edit);
    }
    

    Now I want get information about current syntax type of clicked point or caret position.
    For example, if I click on "class" , I get information "keyword", if I click inside string, get information "string". Is such information available with KF5 Syntax Highlighting or only further - color of theme?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Do you mean you would like the behaviour of a code editor ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • A Offline
        A Offline
        AndrzejB
        wrote on last edited by
        #3

        Most functionality I have search, I found in

        KSyntaxHighlighting::AbstractHighlighter::highlightLine
        

        and virtual applyFormat

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          That does not answer my question.

          QSyntaxHighlighter is a class used to highlight text following some rules, it has no additional knowledge about what it highlights.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          • Login

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