QGraphicsAnchorLayout troubles



  • Hi,

    I have been struggling to get to the anchor layout working for a minimal example and would really appreciate some help.

    Although I have used Qt a fair bit in the past, I have not directly used the layouts much. Most recently I used Qml for a project and really liked the anchor-based layout so I wanted to use the same approach in my current work, which is native Qt. All I am trying to do is create a couple of text items where the horizontal centers are aligned, and the top and bottom edges are aligned. I suspect that I am using the wrong type of objects to make this work, but if that is the case I am not sure what I should be using.

    Here is a snippet of the code that I am using,

    @
    QGraphicsAnchorLayout* layout = new QGraphicsAnchorLayout;
    setLayout(layout);

    QTextEdit* above= new QTextEdit;
    above->setPlainText("Above");
    above->setMaximumHeight(30);

    QGraphicsProxyWidget* above_proxy = new QGraphicsProxyWidget(this);
    above_proxy->setWidget(above);

    QTextEdit* below= new QTextEdit;
    below->setPlainText("Below");
    below->setMaximumHeight(30);

    QGraphicsProxyWidget* below_proxy = new QGraphicsProxyWidget(this);
    below_proxy->setWidget(below);

    layout->setSpacing(0);
    layout->addAnchor(layout, Qt::AnchorHorizontalCenter, above_proxy, Qt::AnchorHorizontalCenter);
    layout->addAnchor(layout, Qt::AnchorHorizontalCenter, below_proxy, Qt::AnchorHorizontalCenter);
    layout->addAnchor(below_proxy, Qt::AnchorTop, above_proxy, Qt::AnchorBottom);
    @

    This code is contained within a QGraphicsWidget and the content is displayed, but it is just the layout that is not doing what I would like. I am using the QGraphicsProxyWidgets because I need something that implements QGraphicsLayoutItem, but I don't know if this is the right thing to do.

    [edit] Sorry, I completely forgot to mention what I am actually observing! With the following code the 'above' and 'below' widgets are horizontally aligned with the layout object, so that much works. However, I cannot get the 'above' and 'below' objects to align relative to one another.

    -Josh


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.