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. QGraphicsItem layouts
Forum Updated to NodeBB v4.3 + New Features

QGraphicsItem layouts

Scheduled Pinned Locked Moved General and Desktop
qgraphicssceneqgraphicsitemqgraphicsviewlayout
2 Posts 2 Posters 2.3k Views 2 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.
  • V Offline
    V Offline
    vityafx4
    wrote on last edited by
    #1

    Unfortunately I can't see any documented information about this.
    I need a layout class like QLayout but not for widgets in widgets but for QGraphicsItem inside QGraphicsItems. I have:

    class AnotherGraphicsItem : public QGraphicsItem {
    public:
        QRectF boundingRect();
    
        void paint(QPainter *painter, ...) {
            painter->drawRect(0, 0, 30, 30);
            // ...
        }
    };
    
    class GraphicsItem : public QGraphicsItem {
    public:
        QRectF boundingRect();
    
        void paint(...) {
            for (size_t i = 0; i < 4; ++i) {
                AnotherGraphicsItem *aItem = new AnotherGraphicsItem();
                aItem->setPos(i * 20, 0);
                aItem->setParent(this);
            }
        }
    };
    
    class GraphicsView : public QGraphicsView {
    public:
        GraphicsView(){ setScene(new QGraphicsScene(this)); populate(); }
        void populate() {
            QGraphicsItem *item = new GraphicsItem();
            scene()->addItem(item);
        }
    };
    

    Briefly, my GraphicsView objects have a scene which has QGraphicsItem objects inside another QGraphicsItem objects

    QGraphicsView -> QGraphicsScene -> QGraphicsItem (GraphicsItem) -> 4x QGraphicsItem (AnotherGraphicsItem)

    The problem is that I need AnotherGraphicsItem to be aligned somehow in the outer GraphicsItem object. I've though to use QGraphicsLayout but it seems it needs to be used inside QGraphicsWidget which I am not gonna use or it works only in QGraphicsView (it has setLayout() method).

    Some good examples are also welcome.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      Asperamanca
      wrote on last edited by
      #2

      You can use QGraphicsLayout classes. These classes require some information about the items they lay out, which is in QGraphicsLayoutItem.
      The simple option is to inherit from QGraphicsWidget (which inherits from QGraphicsLayoutItem), set size policies, fixed/preferred sizes, etc.
      If you don't like to do that for some reason (I don't see any, frankly), you can inherit from QGraphicsLayoutItem directly.

      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