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
    Qt products
    Qt4
    Thanks
    3

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    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.


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

    Default Re: Filling a QGraphicsItem

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

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    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.


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

    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

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

    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.

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

    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.

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

    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.

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    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.


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

    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.

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

    Default Re: Filling a QGraphicsItem

    If you're not able to reimplement painting of the item then you can't fill the item in a loop with 500ms wait. Simple as that.
    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
    Qt products
    Qt4
    Thanks
    3

    Default Re: Filling a QGraphicsItem

    I have reimplemented paint and I have drawn my Item in Paint and i have fill it in one go, which i dont want i want to fill it from mainwindow where a user click fill button then the Item should get filled 10%,20%,30%........100% with 500ms wait this I want to keep in a loop so that i can get filling effect.

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

    Default Re: Filling a QGraphicsItem

    Look, you have been given all the answers you need. We won't code your project for you. At some point (which is now) you have to do some reading to make that little step to be able to code things on your own. Think what is needed to perform such an animation - for sure you need to hold the current state of the fill somewhere in the item and have a method to change that state to the next one. And then you need to periodically call that method that will change the state. If you don't know anything about programming then please post in the newbie section. If you do, then think how to solve your problem - you have already been given the tools you need.
    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. 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
  •  
Qt is a trademark of The Qt Company.