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. [SOLVED] Indent multiple lines with TAB in a QPlainTextEdit
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Indent multiple lines with TAB in a QPlainTextEdit

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 4.9k 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.
  • T Offline
    T Offline
    Threadcore
    wrote on last edited by
    #1

    Hi

    I am very new to Qt and my plan is to write a little text editor for a better understanding in Qt. But I have a little problem with the indentation and the TAB key.

    Is there an easy way to indent multiple (selected) lines with the tab key ? At the moment, it replaces the selected lines with a tab - example:

    Current situation:
    @
    Line 1
    Line 2
    Line 3
    Line 4
    @

    Planed:

    @
    <Tab>Line 1
    <Tab>Line 2
    <Tab>Line 3
    <Tab>Line 4
    @

    But the default behaviour is this, because the 4 lines are replaced with a tab (because they are selected):

    @
    <Tab>
    @

    Is there a way to override this behaviour or to write an indent/outdent function ?

    Greets

    1 Reply Last reply
    0
    • V Offline
      V Offline
      videl
      wrote on last edited by
      #2

      Hello Threadcore,
      You should subclass QPlainTextEdit and override following method:
      @virtual void QPlainTextEdit::keyPressEvent ( QKeyEvent * e )@

      Catch the tab key as described in http://doc.qt.digia.com/qt/qwidget.html#keyPressEvent
      Then you should iterate through selected lines and prepend tab character ('\t').
      You can obtain the selection through a QTextCursor object, which in turn you can obtain by method
      @QTextCursor QPlainTextEdit::textCursor () const@

      1 Reply Last reply
      0
      • T Offline
        T Offline
        Threadcore
        wrote on last edited by
        #3

        Okay, thank you, that's a good starting point

        -PS: Is there a button to mark the thread as solved ?- Titel

        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