There is a form on it QTextEdit (ui-> textEdit); You need to make a frame around the current line (as in Visual Studio)

I do not understand how

There is such an option, but it does not work

void MainWindow::paintEvent ( QPaintEvent * event ) { QPainter painter; painter.begin( ui->textEdit->viewport() ); QRect r = ui->textEdit->cursorRect(); r.setX( 0 ); r.setWidth( ui->textEdit->viewport()->width() ); painter.fillRect( r, QBrush( Qt::blue ) ); } 
  • I am not very good at this, but isn’t that what you need to do with StyleSheet? If more precisely hover ? - Jonathan_Cage
  • There is no object that uniquely describes the string, and objects of type QTextBlock do not have styleSheet - shotInLeg
  • one
    So you have QTextEdit or QTextBlock ? QTextEdit has StyleSheet - ixSci pm
  • I need a frame around the line, not around the text field - shotInLeg

1 answer 1

You are welcome:

 class MyTextEdit: public QTextEdit { protected: void paintEvent(QPaintEvent* event) { QPainter painter(viewport()); QRect r = cursorRect(); r.setX(0); r.setWidth(viewport()->width()); painter.fillRect(r, QBrush(Qt::yellow)); QTextEdit::paintEvent(event); } }; 

enter image description here

  • I understand that I need to use my class "MyTextEdit" everywhere instead of the standard one - shotInLeg
  • For example. You can create eventFilter in MainWindow, intercept QTextEdit redraw events and draw your own - that's enough and move that code. But I like the variant with my own class much more - gil9red