Results 1 to 3 of 3

Thread: QGraphicsView - problems when scrolling text

  1. #1
    Join Date
    May 2010
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QGraphicsView - problems when scrolling text

    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?

    Qt Code:
    1. void CScanWin::paintEvent(QPaintEvent *event)
    2. {
    3. QGraphicsView::paintEvent(event); //pass the event to the graphic view ???
    4.  
    5. QString status = "All Sources available..." + QString::number(q);
    6. QPainter painter(viewport());
    7. painter.setPen(QColor(Qt::yellow));
    8. painter.drawText(10, 10, status);
    9.  
    10. }
    11.  
    12. o
    13. void CScanWin::UpdateDisplay()
    14. {
    15. q++;
    16. cscanScene->clear();
    17. cscanScene->setSceneRect(img->rect());
    18. cscanScene->addPixmap(QPixmap::fromImage(*img));
    19. viewport()->update();
    20.  
    21. }
    To copy to clipboard, switch view to plain text mode 

    Thanks
    Last edited by mlik; 13th May 2010 at 13:21. Reason: updated contents

  2. #2
    Join Date
    May 2010
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QGraphicsView - problems when scrolling text

    Hi

    Anybody have any recommendations?

    Thanks

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QGraphicsView - problems when scrolling text

    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.

Similar Threads

  1. QGraphicsView and Scrolling
    By validator in forum Qt Programming
    Replies: 5
    Last Post: 8th September 2017, 00:27
  2. QGraphicsWidget disappear when scrolling QGraphicsView
    By T4ng10r in forum Qt Programming
    Replies: 10
    Last Post: 21st January 2010, 13:24
  3. Custom scrolling of QGraphicsView
    By hb in forum Qt Programming
    Replies: 0
    Last Post: 12th August 2008, 10:10
  4. QGraphicsView scrolling problem with 4.3.0
    By hb in forum Qt Programming
    Replies: 8
    Last Post: 30th August 2007, 22:18
  5. Replies: 3
    Last Post: 20th February 2007, 13:02

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.