Results 1 to 5 of 5

Thread: QGraphicsItem subclass access to QGraphicsView size

  1. #1
    Join Date
    Sep 2009
    Posts
    30
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default QGraphicsItem subclass access to QGraphicsView size

    Hi,

    I would like to draw an arrow inside a QGraphicsScene linked to a QGraphicsview, but the arrow needs to reach from the left-bottom of the view to the right-bottom of the view. It also needs to move and stay +/- 10 pixels above the bottom. It should always be in view, but resize only one line (no transformation).
    Something like this:
    |-------------------->|
    resized:
    |---------------------------------------->|
    note the arrow pointer thing (>) has not changed size.
    It almost seems like I need to make a QPainterPath with three lineTo's and one moveTo, where one lineTo is subject to normal transformation, but the rest isn't.
    My conclusion would be QPainterPath isn't what I'm looking for; maybe a QList<QGrapicsLineItem> is what I need. What do you think?

    Thanks

  2. #2
    Join Date
    Oct 2009
    Location
    Mexico
    Posts
    81
    Thanks
    6
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsItem subclass access to QGraphicsView size

    if only need to draw a arrow in the top of the view is more simple subclass a view and draw the arrow in the drawForeground() function

    Qt Code:
    1. class CustomView : public QGraphicsView
    2. {
    3. public:
    4. explicit CustomView ( QWidget * parent = 0 )
    5. : QGraphicsView (parent){};
    6.  
    7. protected:
    8. void drawForeground ( QPainter * painter, const QRectF & rect )
    9. {
    10. painter->setPen(QPen(Qt::red,3));
    11. painter->drawLine( rect.topLeft(), rect.bottomRight() );
    12. painter->drawLine( rect.topRight(), rect.bottomLeft() );
    13. }
    14. };
    To copy to clipboard, switch view to plain text mode 


    this draw a big X in the view.
    convert the code to draw a arrow must be trivial. but is late and i want to sleep
    Last edited by ecanela; 22nd January 2010 at 06:23. Reason: updated contents

  3. The following user says thank you to ecanela for this useful post:

    rubenvb (23rd January 2010)

  4. #3
    Join Date
    Sep 2009
    Posts
    30
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGraphicsItem subclass access to QGraphicsView size

    That looks like a good idea, that way I won't have to worry about getting parent widget coordinates.

    One question though: will it be possible to "print" the whole scene (including the arrows) to an image, or will the arrow not be included because it's not part of the scene?

    Thanks!

  5. #4
    Join Date
    Sep 2009
    Posts
    30
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGraphicsItem subclass access to QGraphicsView size

    Note to self, must read docs:
    http://doc.trolltech.com/4.2/qgraphicsview.html#render

    It is the view that is rendered to the printer, not the scene, so drawing on the foreground it is!

    thanks again

  6. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QGraphicsItem subclass access to QGraphicsView size

    There is also QGraphicsScene::render().
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. QGraphicsView, QGraphicsItem, QGraphicsScene
    By Shuchi Agrawal in forum Newbie
    Replies: 10
    Last Post: 23rd March 2011, 20:50
  2. Replies: 5
    Last Post: 31st December 2010, 11:49
  3. Animation of QGraphicsItem in QGraphicsView
    By mirelon in forum Qt Programming
    Replies: 4
    Last Post: 19th December 2009, 15:25
  4. Multiple inheritance of QGraphicsView and QGraphicsItem
    By cookie1909 in forum Qt Programming
    Replies: 9
    Last Post: 15th May 2009, 18:02
  5. (QT4.2-RC1) QGraphicsScene QGraphicsView QGraphicsItem
    By antonio.r.tome in forum Qt Programming
    Replies: 1
    Last Post: 20th September 2006, 10:56

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.