Solved Drawing a vertical line on a QPlainTextEdit?
-
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:
-
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