Results 1 to 20 of 29

Thread: Drawing on QGraphicsView

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2007
    Posts
    19
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    5
    Thanked 1 Time in 1 Post

    Default Re: Drawing on QGraphicsView

    I am also having the task of drawing an axis scale on a QGraphicsView, that is supposed to be at a fixed widget position, with fixed linewidth etc. I think I finally found a solution. Basically, you can just override drawForeground, turn off the world coordinate system mapping and draw directly in view coordinates. The following code would for example draw the axes as two plain lines:

    Qt Code:
    1. void myGraphicsView::drawForeground(QPainter *painter, const QRectF &rect)
    2. {
    3. int axesOffset = 10;
    4. int bottom = height() - 2*axesOffset;
    5. int right = width() - 2*axesOffset;
    6.  
    7. painter->setWorldMatrixEnabled(false);
    8. painter->setPen(Qt::white);
    9. painter->drawLine(axesOffset,axesOffset,axesOffset,bottom);
    10. painter->drawLine(axesOffset,bottom,right,bottom);
    11. }
    To copy to clipboard, switch view to plain text mode 

  2. The following user says thank you to hb for this useful post:

    JonathanForQT4 (8th June 2007)

Similar Threads

  1. [SOLVED] QTreeView drawing selection with icons
    By Timewarp in forum Qt Programming
    Replies: 7
    Last Post: 7th February 2013, 07:52
  2. Drawing the background of QGraphicsView
    By aknuds1 in forum Qt Programming
    Replies: 13
    Last Post: 9th March 2007, 14:53
  3. Using QGraphicsView with model/view programming
    By JLP in forum Qt Programming
    Replies: 3
    Last Post: 29th January 2007, 11:04
  4. Drawing on QWidget - strech & resize
    By kemp in forum Qt Programming
    Replies: 5
    Last Post: 22nd January 2007, 14:39
  5. Regarding QGraphicsView
    By kiranraj in forum Qt Programming
    Replies: 4
    Last Post: 22nd December 2006, 04:59

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
  •  
Qt is a trademark of The Qt Company.