Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] How to paint a QGraphicsItemGroup object?
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] How to paint a QGraphicsItemGroup object?

Scheduled Pinned Locked Moved General and Desktop
qgraphicsitemgr
2 Posts 1 Posters 1.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    xtingray
    wrote on last edited by xtingray
    #1

    Hi,
    Currently I am programming a basic dialog to visualize a QGraphicsItem object. Using the paint() method is working pretty well with the single items:

    QGraphicsItem *item;
    ...
    item->paint(painter, option, widget);
    

    My problem occurs when I try to visualize a QGraphicsItemGroup object, I don't get any error message but only an empty area, if I try this code:

    QGraphicsItemGroup *group;
    ...
    group->paint(painter, option, widget);
    

    So, I would like to know what is the right way to paint a group in this context? Thanks.


    Qt Developer

    1 Reply Last reply
    0
    • X Offline
      X Offline
      xtingray
      wrote on last edited by
      #2

      Finally, I found a nice way to visualize a QGraphicsItemGroup in an accurate way. Here is the code:

         if (QGraphicsItemGroup *group = qgraphicsitem_cast<QGraphicsItemGroup *>(item)) {
              foreach (QGraphicsItem *child, group->childItems())
                       child->paint(painter, option, widget);
          } else {
              item->paint(painter, option, widget);
          }
      

      I hope this trick can be useful for somebody else ;)


      Qt Developer

      1 Reply Last reply
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved