Hi to all,
I attached a QWidget to a scrollarea. The widget is scrolled automatically and I draw a text on the position 20, 20.
The problem is that when the widget is scrolled the text disappear. I draw the text in the paint event so:
{
if( m_waveCachePixmap.isNull() )
{
updateWave();
}
p.
setRenderHint( QPainter::Antialiasing,
true );
// wave
p.drawPixmap( 0, 0, m_waveCachePixmap );
// timeline
pen.setColor(Qt::darkRed);
pen.setStyle(Qt::SolidLine);
p.setPen( pen );
p.drawLine( m_CurrentTimePosition, 0, m_CurrentTimePosition, height() );
// elapsed time
QWidget* widget
= area
->viewport
();
//HOW CAN I USE THE VIEW PORT setElapsedTime( m_CurrentSoundPosition );
font.setPointSize( 24 );
p.setFont( font );
p.
drawText( QPoint(20,
20), m_elapsedTimeString
);
//THE TEXT DISAPPEAR
}
void WaveDisplay::paintEvent( QPaintEvent* pe )
{
if( m_waveCachePixmap.isNull() )
{
updateWave();
}
QPainter p( this );
p.setRenderHint( QPainter::Antialiasing, true );
QPen pen = QPen( Qt::darkRed, 1 );
// wave
p.drawPixmap( 0, 0, m_waveCachePixmap );
// timeline
pen.setColor(Qt::darkRed);
pen.setStyle(Qt::SolidLine);
p.setPen( pen );
p.drawLine( m_CurrentTimePosition, 0, m_CurrentTimePosition, height() );
// elapsed time
QWidget* widget = area->viewport(); //HOW CAN I USE THE VIEW PORT
setElapsedTime( m_CurrentSoundPosition );
QFont font = p.font();
font.setPointSize( 24 );
p.setFont( font );
p.drawText( QPoint(20, 20), m_elapsedTimeString ); //THE TEXT DISAPPEAR
QWidget::paintEvent(pe);
}
To copy to clipboard, switch view to plain text mode
I read about the viewport but I don't know how use it for my purpose.
I would always draw at a position of the viewport of my scrollarea.
regards
Bookmarks