Results 1 to 3 of 3

Thread: QGraphicsWidget shape only works down right from center

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,321
    Thanks
    316
    Thanked 871 Times in 858 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QGraphicsWidget shape only works down right from center

    Move your ellipse up and to the left by 50 each:

    Qt Code:
    1. path.addEllipse( QRectF( 0, 0, 100, 100 ) );
    To copy to clipboard, switch view to plain text mode 
    Last edited by d_stranz; 7th February 2013 at 22:11.

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

    Default Re: QGraphicsWidget shape only works down right from center

    Quote Originally Posted by d_stranz View Post
    Move your ellipse up and to the left by 50 each:

    Qt Code:
    1. path.addEllipse( QRectF( 0, 0, 100, 100 ) );
    To copy to clipboard, switch view to plain text mode 
    Hmmm.... why so?

    This works perfectly fine:

    Qt Code:
    1. #include <QtGui>
    2.  
    3. class Item : public QGraphicsItem {
    4. public:
    5. Item(QGraphicsItem *parent = 0) : QGraphicsItem(parent) {}
    6. QRectF boundingRect() const { return QRectF(-50, -50, 100, 100); }
    7. QPainterPath shape() const { QPainterPath p; p.addEllipse(boundingRect()); return p; }
    8. void paint(QPainter *p, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) {
    9. p->drawEllipse(boundingRect());
    10. }
    11. protected:
    12. void mousePressEvent(QGraphicsSceneMouseEvent *e) {
    13. qDebug() << Q_FUNC_INFO;
    14. }
    15. };
    16.  
    17. int main(int argc, char **argv) {
    18. QApplication app(argc, argv);
    19. view.setScene(&sc);
    20. sc.addItem(new Item);
    21. view.show();
    22. return app.exec();
    23. }
    To copy to clipboard, switch view to plain text mode 
    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. Replies: 3
    Last Post: 6th July 2011, 06:59
  2. Qml in QGraphicsWidget
    By animagani in forum Qt Quick
    Replies: 7
    Last Post: 2nd December 2010, 16:20
  3. QGraphicsWidget and ItemIsMovable()
    By paolom in forum Qt Programming
    Replies: 8
    Last Post: 20th October 2009, 13:25
  4. QTextEdit on a QGraphicsWidget
    By paolom in forum Qt Programming
    Replies: 2
    Last Post: 7th October 2009, 14:08
  5. QGraphicsWidget - How does it work?
    By been_1990 in forum Qt Programming
    Replies: 2
    Last Post: 31st July 2009, 13:15

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.