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:
ui->radar_gw->setScene(l_scene);
ui
->radar_gw
->setRenderHints
(QPainter::Antialiasing);
m_main_offset = 2;
m_north_space_px = 12;
m_radar_gui_diameter = ui->radar_gw->width()-(m_north_space_px*2)-m_main_offset;
m_radar_gui_radius = m_radar_gui_diameter * 0.5;
//MAIN CIRCLE
l_radar_circle
->setPen
(QPen(QColor(Qt
::green),
2));
l_scene->addItem(l_radar_circle);
//NORTH
QPixmap l_north_pix
(":/background/north.png");
l_north_lbl->setAutoFillBackground(false);
l_north_lbl->setPixmap(l_north_pix.scaled(m_north_space_px, m_north_space_px, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
QGraphicsProxyWidget* l_north_widget = l_scene->addWidget(l_north_lbl);
l_north_widget->setPos(m_radar_gui_radius - m_north_space_px*0.5, 0);
QGraphicsScene* l_scene = new QGraphicsScene(this);
ui->radar_gw->setScene(l_scene);
ui->radar_gw->setRenderHints(QPainter::Antialiasing);
m_main_offset = 2;
m_north_space_px = 12;
m_radar_gui_diameter = ui->radar_gw->width()-(m_north_space_px*2)-m_main_offset;
m_radar_gui_radius = m_radar_gui_diameter * 0.5;
//MAIN CIRCLE
QGraphicsEllipseItem* l_radar_circle = new QGraphicsEllipseItem(0, 0, m_radar_gui_diameter, m_radar_gui_diameter);
l_radar_circle->setPen(QPen(QColor(Qt::green), 2));
l_scene->addItem(l_radar_circle);
//NORTH
QPixmap l_north_pix(":/background/north.png");
QLabel* l_north_lbl = new QLabel();
l_north_lbl->setAutoFillBackground(false);
l_north_lbl->setPixmap(l_north_pix.scaled(m_north_space_px, m_north_space_px, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
QGraphicsProxyWidget* l_north_widget = l_scene->addWidget(l_north_lbl);
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:
l_north_widget->setPos(m_radar_gui_radius - m_north_space_px*0.5, 0);
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:
l_north_widget->setPos(m_radar_gui_radius - m_north_space_px*0.5, -m_north_space_px-m_main_offset);
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
Bookmarks