PDA

View Full Version : QGraphicsView - problems when scrolling text



mlik
13th May 2010, 09:41
Hi

I am having problems displaying a text string in the top left hand corner of my QGraphicsView widget. When scrolling the text scrolls as well, I would like the text to stay in position at the top left hand corner of the widget.

UpdateDisplay is called when an image is ready for display, this forces the paint event for the QGraphicsView

My code is below, what am I doing wrong?


void CScanWin::paintEvent(QPaintEvent *event)
{
QGraphicsView::paintEvent(event); //pass the event to the graphic view ???

QString status = "All Sources available..." + QString::number(q);
QPainter painter(viewport());
painter.setPen(QColor(Qt::yellow));
painter.drawText(10, 10, status);

}

o
void CScanWin::UpdateDisplay()
{
q++;
cscanScene->clear();
cscanScene->setSceneRect(img->rect());
cscanScene->addPixmap(QPixmap::fromImage(*img));
viewport()->update();

}


Thanks

mlik
14th May 2010, 09:22
Hi

Anybody have any recommendations?

Thanks

Lykurg
14th May 2010, 09:53
Well, I do not understand your architecture. Therefore, what I would do:
Insert your text as a QGraphicsTextItem (or any other item class) to your scene. From your view use the signal: QAbstractScrollArea::verticalScrollBar() -> QAbstractSlider::valueChanged() and react on it by moving your item.