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 add widget inside editor widget ? (line numbers)
Forum Updated to NodeBB v4.3 + New Features

How add widget inside editor widget ? (line numbers)

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 1.3k Views 2 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

    I try add line numbers to QTextEdit:
    [https://gist.github.com/borneq/0bf62c320d12b66f88a2b260a5e9f322](link url)
    I have add :

    NumberedEdit::NumberedEdit(QWidget *parent) : QTextEdit(parent)
    {
        lineNumberArea = new LineNumberArea(this);
        connect(this, SIGNAL(blockCountChanged(int)), this, SLOT(updateLineNumberAreaWidth(int)));
        connect(this, SIGNAL(updateRequest(QRect,int)), this, SLOT(updateLineNumberArea(QRect,int)));
        connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(highlightCurrentLine()));
    
        updateLineNumberAreaWidth(0);    
    }
    

    I have lineNumberArea = new LineNumberArea(this); but is collision this widget with textarea. How do child widget similar scrollbars? Or other way to make text margin?

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

      Hi,

      Looks like the Code Editor Example, is it ?

      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
      2
      • A Offline
        A Offline
        AndrzejB
        wrote on last edited by AndrzejB
        #3

        I based on it but have changed editor widget from QPlainTextEdit to QTextEdit which enables syntax highlighting. Code Editor Example has not problems with lineNumberArea ?
        Now (today) this example is good (still some little problems as refreshing line numbers). I don't know why today works if not work previously...

        I know! if

        int space = 3 + fontMetrics().width(QLatin1Char('9')) * digits;
        

        will constants it will be good, but at start editor is empty and digit==1, and space == 9 but next call increases space but not increases margin. How correct it?

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

          Which version of Qt are you using ?
          On which platform ?

          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 AndrzejB
            #5

            Qr 5.10.0 on Windows. Problem is with changing space. First calling lineNumberAreaWidth() set margin, next callings not set.
            Qt calls sizeHint() of LineNumberArea, but not changed size of editor object.

            1 Reply Last reply
            0
            • A AndrzejB

              I based on it but have changed editor widget from QPlainTextEdit to QTextEdit which enables syntax highlighting. Code Editor Example has not problems with lineNumberArea ?
              Now (today) this example is good (still some little problems as refreshing line numbers). I don't know why today works if not work previously...

              I know! if

              int space = 3 + fontMetrics().width(QLatin1Char('9')) * digits;
              

              will constants it will be good, but at start editor is empty and digit==1, and space == 9 but next call increases space but not increases margin. How correct it?

              M Offline
              M Offline
              mpergand
              wrote on last edited by
              #6

              have changed editor widget from QPlainTextEdit to QTextEdit which enables syntax highlighting.

              Syntax highlighting works well with QPlainTextEdit. You need QTextEdit only if you want Rich Text capabilities.

              The problem with TextEdit is that the signals are not the same.
              Anyway, someone did the job:
              https://stackoverflow.com/questions/2443358/how-to-add-lines-numbers-to-qtextedit

              A 1 Reply Last reply
              2
              • M mpergand

                have changed editor widget from QPlainTextEdit to QTextEdit which enables syntax highlighting.

                Syntax highlighting works well with QPlainTextEdit. You need QTextEdit only if you want Rich Text capabilities.

                The problem with TextEdit is that the signals are not the same.
                Anyway, someone did the job:
                https://stackoverflow.com/questions/2443358/how-to-add-lines-numbers-to-qtextedit

                A Offline
                A Offline
                AndrzejB
                wrote on last edited by
                #7

                @mpergand said in How add widget inside editor widget ? (line numbers):

                have changed editor widget from QPlainTextEdit to QTextEdit which enables syntax highlighting.

                Thanks! It helps and already line numbers are OK!

                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