Results 1 to 16 of 16

Thread: Filling a QGraphicsItem

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2008
    Posts
    52
    Thanks
    3
    Qt products
    Qt4

    Default Filling a QGraphicsItem

    Hi,
    I want to fill a GraphicsItem with a color but not completly i want to fill it based on user choice i.e if user want to fill only 50% of a Item the Item should get filled only partially.
    How is this possible
    Check the attached image.
    Attached Images Attached Images

  2. #2
    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: Filling a QGraphicsItem

    Reimplement the paint routine for the item and paint it properly. What did you try already?
    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.


  3. #3
    Join Date
    Dec 2008
    Posts
    52
    Thanks
    3
    Qt products
    Qt4

    Default Re: Filling a QGraphicsItem

    Thanks for reply.
    Actually I am reimplementing the Diagram Scene Example. I want to fill only some region of graphics item. I have not found any methods to that, except setBrush which fill complete item.
    My aim is to fill continuously from 0 to 100 % of an Item.
    How can I do it.

  4. #4
    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: Filling a QGraphicsItem

    I already told you how. Reimplement the paint() rountine, calculate the shape that is to be filled and use QPainter API to do the drawing, probably using QPainter::drawPolygon().
    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.


  5. #5
    Join Date
    Dec 2008
    Posts
    52
    Thanks
    3
    Qt products
    Qt4

    Default Re: Filling a QGraphicsItem

    But I want to retain its original shape.
    Attached Images Attached Images

  6. #6
    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: Filling a QGraphicsItem

    My answer still stands. And if you want to do it another way then apply clipping to the painter according to the part you want to fill and fill the whole item.
    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.


  7. #7
    Join Date
    Dec 2008
    Posts
    52
    Thanks
    3
    Qt products
    Qt4

    Default Re: Filling a QGraphicsItem

    if I impliment in this loop my Item should be filled in 5 loops as in attached image
    Attached Images Attached Images

  8. #8
    Join Date
    Dec 2008
    Posts
    52
    Thanks
    3
    Qt products
    Qt4

    Default Re: Filling a QGraphicsItem

    As you know that in DiagramScene example I have a MainWindow in that DiagramScene on that with mousce click I am placing DiagramItem which is a QGraphicsPolygonItem in that class there is no paint() only setPolygon is there.
    So do i have to implement Paint() and if i write my fillItem() in MainWindow then i have to call Item's paint in a loop to get the effact i want.
    can u just show me sample code.
    Thank u,
    regards.

  9. #9
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Filling a QGraphicsItem

    QGraphicsPolygonItem is inherited from QGraphicsItem and hence you can always override the paint function.

    You will need to inherit from QGraphicsPolygonItem and reimplement paint function.
    In that paint function u can call the base class paint function and then fill the desired area in your class paint function.

  10. #10
    Join Date
    Dec 2008
    Posts
    52
    Thanks
    3
    Qt products
    Qt4

    Default Re: Filling a QGraphicsItem

    If I do so then the Paint Function of the Item is called only once when it is created. Then how can I show the Filling effect on the scene. I fill the Item in a loop with some delay in each filling untill its full.

  11. #11
    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: Filling a QGraphicsItem

    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.


  12. #12
    Join Date
    Dec 2008
    Posts
    52
    Thanks
    3
    Qt products
    Qt4

    Default Re: Filling a QGraphicsItem

    Thanx for reply, but I am not able to form the paint logic, plz help to to fill item in a loop with 500ms wait.

Similar Threads

  1. QGraphicsItem doesn't inherit QObject?
    By xyzt in forum Qt Programming
    Replies: 6
    Last Post: 26th September 2011, 14:59
  2. Replies: 2
    Last Post: 25th March 2011, 09:18
  3. destruction of QGraphicsItem
    By killkolor in forum Qt Programming
    Replies: 2
    Last Post: 5th December 2009, 10:31
  4. Replies: 11
    Last Post: 2nd July 2009, 00:41
  5. Replies: 1
    Last Post: 25th February 2009, 00:34

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.