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. Drawing a vertical line on a QPlainTextEdit?
Forum Updated to NodeBB v4.3 + New Features

Drawing a vertical line on a QPlainTextEdit?

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 872 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.
  • F Offline
    F Offline
    Fuchsiaff
    wrote on last edited by
    #1

    Is it possible to draw a vertical line on a QPlainTextEdit so that it wouldn't prevent people from writing text on top of it? I'm aiming for something like this:
    0_1547487866246_3ff73820-f352-45de-98f0-93f9f822f67e-image.png

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

      Hi
      Sure it is. Fast sample. Note. using fixed numbers. you want to use viewport()->height() etc.

      #ifndef MYTEXT_H
      #define MYTEXT_H
      
      #include <QPainter>
      #include <QPlainTextEdit>
      class MyText : public QPlainTextEdit
      {
          Q_OBJECT
      public:
          explicit MyText(QWidget *parent = nullptr) : QPlainTextEdit(parent) {}
      protected:
          virtual void paintEvent(QPaintEvent *event) override
          {
              QPlainTextEdit::paintEvent(event);
              QPainter p(viewport()); // note we use viewport as its the one that actually draws
              p.drawLine(100, 0, 100, 1000);
      
          }
      };
      
      #endif // MYTEXT_H
      
      

      alt text

      1 Reply Last reply
      1

      • Login

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