Results 1 to 8 of 8

Thread: Custom QGraphicsRectItem with size grip

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2009
    Location
    Dundee, United Kingdom
    Posts
    18
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    4

    Default Re: Custom QGraphicsRectItem with size grip

    Hi,
    Thanks for the help - yes, I had a look at the source of QStyleOption and QSizeGrip... In QStyleOption the init() method gets the different style settings from a widget (rect, direction, font metrics etc.). I also tried adding the QWidget as base class to MyRectangle, but it didn't change anything...

    Qt Code:
    1. void MyRectangle::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *)
    2. {
    3. opt.corner = Qt::BottomLeftCorner;
    4. opt.rect = boundingRect().toRect();
    5. opt.direction = QApplication::layoutDirection();
    6. opt.palette = QApplication::palette();
    7. opt.fontMetrics = QApplication::fontMetrics();
    8. opt.state = option->state;
    9. pen.setStyle(Qt::SolidLine);
    10. pen.setColor(QColor(Qt::black));
    11. pen.setWidth(1);
    12. if(option->state & QStyle::State_Selected)
    13. {
    14. pen.setStyle(Qt::DashLine);
    15. pen.setColor(QColor(Qt::green));
    16. }
    17. painter->setPen(pen);
    18. QApplication::style()->drawControl(QStyle::CE_SizeGrip, &opt, painter);
    19. painter->drawRect(this->boundingRect());
    20. }
    To copy to clipboard, switch view to plain text mode 

    As you see I'm taking the settings from QApplication. The only problem is with the bounding rectangle. MyRectangles are created with another QGraphicsPixmapItem as a parent (rectangles on an image). The size grip tends to begin inside every rectangle and finish at the top of the parent image... There must be something wrong with the coordinates...

    If you have any other suggestions, please reply.
    Any help appreciated.

    Regards,
    Bill

  2. #2
    Join Date
    Jul 2009
    Location
    Dundee, United Kingdom
    Posts
    18
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    4

    Default Re: Custom QGraphicsRectItem with size grip

    Ok,
    I can consider this topic closed... I found here http://www.qtcentre.org/forum/f-qt-p...pes-18238.html exactly what I needed
    Still - if someone finds a way to draw the QSizeGrip on QGraphicItems - I will be more than happy and grateful to know the solution.

    Cheers,
    Bill

Similar Threads

  1. resizing widgets depending on a main widget size
    By luf in forum Qt Programming
    Replies: 6
    Last Post: 10th October 2009, 16:13
  2. Replies: 7
    Last Post: 28th May 2009, 23:49
  3. QLabel size policy
    By Caius Aérobus in forum Qt Programming
    Replies: 3
    Last Post: 7th December 2007, 17:57
  4. Simple custom widget won't size properly
    By MrGarbage in forum Qt Tools
    Replies: 2
    Last Post: 9th August 2007, 13:12
  5. size issues for custom QWidget in QScrollArea
    By anotheruser in forum Qt Programming
    Replies: 1
    Last Post: 27th April 2006, 14:52

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.