Results 1 to 2 of 2

Thread: QGraphicsScene: adding QGraphicsProxyWidget moves others QGraphicsEllipseItem

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2021
    Posts
    1
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default QGraphicsScene: adding QGraphicsProxyWidget moves others QGraphicsEllipseItem

    Hi,

    Sorry for the silly question but I'm working with QGraphicsScene and I have "weird" behaviours that I don't understand at all.

    Basically I have a simple radar representation with a main "circle" and an icon which represent the North direction.

    So I have somthing like this:

    Qt Code:
    1. QGraphicsScene* l_scene = new QGraphicsScene(this);
    2. ui->radar_gw->setScene(l_scene);
    3. ui->radar_gw->setRenderHints(QPainter::Antialiasing);
    4.  
    5. m_main_offset = 2;
    6. m_north_space_px = 12;
    7.  
    8. m_radar_gui_diameter = ui->radar_gw->width()-(m_north_space_px*2)-m_main_offset;
    9. m_radar_gui_radius = m_radar_gui_diameter * 0.5;
    10.  
    11. //MAIN CIRCLE
    12. QGraphicsEllipseItem* l_radar_circle = new QGraphicsEllipseItem(0, 0, m_radar_gui_diameter, m_radar_gui_diameter);
    13. l_radar_circle->setPen(QPen(QColor(Qt::green), 2));
    14. l_scene->addItem(l_radar_circle);
    15.  
    16. //NORTH
    17. QPixmap l_north_pix(":/background/north.png");
    18. QLabel* l_north_lbl = new QLabel();
    19. l_north_lbl->setAutoFillBackground(false);
    20. l_north_lbl->setPixmap(l_north_pix.scaled(m_north_space_px, m_north_space_px, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
    21. QGraphicsProxyWidget* l_north_widget = l_scene->addWidget(l_north_lbl);
    22. l_north_widget->setPos(m_radar_gui_radius - m_north_space_px*0.5, 0);
    To copy to clipboard, switch view to plain text mode 

    Basically this code display something like this:

    1.jpg

    There is a first question:

    Qt Code:
    1. l_north_widget->setPos(m_radar_gui_radius - m_north_space_px*0.5, 0);
    To copy to clipboard, switch view to plain text mode 

    This setPos is relative to the QGraphicsEllipseItem (l_radar_circle) dimensions and NOT to the main QGraphicsView container. Why?!? l_radar_circle is added to l_scene (QGraphicsScene) not to the QGraphicsEllipseItem. Where I'm in wrong?

    -----

    As you can see in the previous image, I've left the space to show the North icon outside the circle (because the North icon can move around the main circle).
    So, I've tried to move up the North icon like this:

    Qt Code:
    1. l_north_widget->setPos(m_radar_gui_radius - m_north_space_px*0.5, -m_north_space_px-m_main_offset);
    To copy to clipboard, switch view to plain text mode 

    And this is the result:

    2.jpg

    The main l_radar_circle as moved down, like the l_north_widget interacts with the l_radar_circle (and then there is not enough space at the bottom of l_radar_circle). I don't want this behaviour, just as I don't want the previous case where the North widget is relative to the main circle item.

    Can you address me a way to achieve a correct beahviour? Basically, I need a method to freely draw shapes and textures without "shadow" layout and "weird" reparenting. I have to go with OpenGL directly?

    Many thanks, bye
    Last edited by Doxy82; 9th September 2021 at 21:40.

Similar Threads

  1. Replies: 5
    Last Post: 3rd April 2019, 17:34
  2. Replies: 1
    Last Post: 9th September 2016, 08:46
  3. Screenshot of QGraphicsScene with QGraphicsProxyWidget
    By anirudh123 in forum Qt Programming
    Replies: 2
    Last Post: 14th July 2016, 11:56
  4. Replies: 8
    Last Post: 9th July 2010, 00:37
  5. Adding QGraphicsProxyWidget items into QGraphicsScene
    By yagabey in forum Qt Programming
    Replies: 3
    Last Post: 21st November 2008, 06:33

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.