Results 1 to 3 of 3

Thread: QGraphicsWidget shape only works down right from center

  1. #1
    Join Date
    Feb 2013
    Posts
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default QGraphicsWidget shape only works down right from center

    Hello,
    I have made custom graphics widget with:

    Qt Code:
    1. QRectF graphicsTask::boundingRect()
    2. {
    3. return QRectF(-50, -50, 100, 100);
    4. }
    5.  
    6. QPainterPath graphicsTask::shape()
    7. {
    8. path.addEllipse(boundingRect());
    9. return path;
    10. }
    To copy to clipboard, switch view to plain text mode 

    but it gets mouse events only on part of shape down and right of center of the item (bottom right quarter of a circle).
    How can I make it work on all shape?

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 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.

  3. #3
    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: 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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.