Results 1 to 3 of 3

Thread: Drawing a custom QGraphicsItem

  1. #1
    Join Date
    Jul 2012
    Location
    UK
    Posts
    17
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Drawing a custom QGraphicsItem

    Dear QtCummunity,

    I would like to draw a custom item like the attached image. Request your suggestion please.

    Qt Code:
    1. void MyItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
    2. {
    3. // Please suggest me
    4.  
    5. }
    To copy to clipboard, switch view to plain text mode 
    Attached Images Attached Images
    Last edited by saifulkhan; 12th March 2013 at 19:24.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,330
    Thanks
    317
    Thanked 871 Times in 858 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Drawing a custom QGraphicsItem

    Use QPainter::drawLine(), QPainter::drawRect(), and QPainter::drawPolygon() (for the triangle). Use whatever dimensions are the most convenient for your application, since all of the transformations to set position, scale, and rotation are done by the parent of your MyItem.

  3. #3
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 453 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Drawing a custom QGraphicsItem

    Do you want to paint it as a single item? then use QPainterPath(s)

    You could also use multiple QGrpahicsLineItems, and use QPen and QBrush settings as needed.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  4. The following user says thank you to Santosh Reddy for this useful post:

    saifulkhan (17th March 2013)

Similar Threads

  1. Problem with derived class from QGraphicsItem and drawing
    By airglide in forum Qt Programming
    Replies: 6
    Last Post: 19th February 2013, 03:20
  2. Drawing on QGraphicsItem.
    By ommharidaas in forum Qt Programming
    Replies: 9
    Last Post: 21st September 2011, 13:40
  3. Replies: 7
    Last Post: 5th June 2011, 20:12
  4. Drawing standard widgets using a custom paint engine
    By Waywocket in forum Qt Programming
    Replies: 26
    Last Post: 21st October 2010, 20:40
  5. Custom QGraphicsItem
    By Lis in forum Qt Programming
    Replies: 1
    Last Post: 12th April 2010, 03:47

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.