jdowner last edited by
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;
QTextEdit* above= new QTextEdit;
QGraphicsProxyWidget* above_proxy = new QGraphicsProxyWidget(this);
QTextEdit* below= new QTextEdit;
QGraphicsProxyWidget* below_proxy = new QGraphicsProxyWidget(this);
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.
 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.