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. QGraphicsAnchorLayout troubles
Qt 6.11 is out! See what's new in the release blog

QGraphicsAnchorLayout troubles

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 934 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.
  • J Offline
    J Offline
    jdowner
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0

    • Login

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