In QPlainTextEdit
first typed symbol is drawn with a small offset, literally there a few pixels. But how to know the value of this offset in the code? Look at the screenshot, distance between red line and selected character is what I need to know.
A code to play with it:
<code>#include <QApplication>
#include <QPlainTextEdit>
#include <QPainter>
class TextEdit
: public QPlainTextEdit
{
protected:
void paintEvent( QPaintEvent * e ) override
{
QPainter p( viewport() );
p.setPen( Qt::red );
p.drawRect( viewport()->rect() );
QPlainTextEdit::paintEvent( e );
}
};
int main( int argc, char ** argv )
{
QApplication app( argc, argv );
TextEdit e;
e.resize( 100, 100 );
e.show();
return QApplication::exec();
}
</code>
<code>#include <QApplication>
#include <QPlainTextEdit>
#include <QPainter>
class TextEdit
: public QPlainTextEdit
{
protected:
void paintEvent( QPaintEvent * e ) override
{
QPainter p( viewport() );
p.setPen( Qt::red );
p.drawRect( viewport()->rect() );
QPlainTextEdit::paintEvent( e );
}
};
int main( int argc, char ** argv )
{
QApplication app( argc, argv );
TextEdit e;
e.resize( 100, 100 );
e.show();
return QApplication::exec();
}
</code>
#include <QApplication>
#include <QPlainTextEdit>
#include <QPainter>
class TextEdit
: public QPlainTextEdit
{
protected:
void paintEvent( QPaintEvent * e ) override
{
QPainter p( viewport() );
p.setPen( Qt::red );
p.drawRect( viewport()->rect() );
QPlainTextEdit::paintEvent( e );
}
};
int main( int argc, char ** argv )
{
QApplication app( argc, argv );
TextEdit e;
e.resize( 100, 100 );
e.show();
return QApplication::exec();
}
viewportMargins().left()
, contentsMargins().left()
are 0.
What else?
Thank you.