PDA

View Full Version : problem about QMultiLineEdit



qtopiahooo
14th November 2006, 01:59
hi, all

I have a problem now.

I want to subclass QMultiLineEdit which paint a line underneath every row on the editable area just like a notebook. i haven't found out how to implement it. maybe i can rewrite the paintEvent, but i'm not sure.

any help is appreciated.

tbscope
14th November 2006, 09:41
That will probably work.

In pseudo code:


yourclass::paintevent(event e)
{
qmultilineedit::paintevent(e);

getFontHeight();
addSomeOffset();

setPenColor();

for( every line on the visible display )
{
drawLineAtFontHeight+OffSet();
}
}

qtopiahooo
16th November 2006, 07:12
Thanks.

I subclass QMultiLineEdit, and reimplement the paintEvent member funtion. it does paint lines under every row.

howerver, once the text is more than one page, and the vertical scrollbar is needed, there are more lines than expected. maybe it is left by the last time. then i record the positions of drawn lines and repaint them with the base color before the current lines' drawing, but i doesn't work.

i don't know how to solve it. the following is the code of the original.


void MultiLineEdit::paintEvent(QPaintEvent *e)
{
QMultiLineEdit::paintEvent(e);

QPainter painter(viewport());
painter.setPen(Qt::black);

QFontMetrics fm( painter.font() );
int rowHeight = fm.height()+ fm.leading();
int col = height()/rowHeight;
for( int i = 1; i <= col; i++ )
painter.drawLine( 0, i*rowHeight, width(), i*rowHeight );
}

thanks in advance.