Unsolved Image Overlap Problem in QGraphicsScene
-
Hi,
I try to develop a transparent hud. And i face an overlapping problem that can be seen from the image:
I derived the HUD_Scene class from the QGraphicsScene. The HUD_Scene class contains the symbologies. The symbologies are derived from QWidget and then added the scene with the help of addWidget() function. In the symbologies' classes, i draw the values and the symbology visuals with the help of QPainter in paintEvent().The general view of HUD_Scene can be seen at below.
//Header File #ifndef HUD_SCENE_HPP #define HUD_SCENE_HPP #include <QtWidgets/QGraphicsScene> class QWidget; class QGraphicsView; class QGraphicsProxyWidget; class QTimer; class QDialog; class HUD_Scene :public QGraphicsScene { Q_OBJECT public: HUD_Scene(QObject *parent = Q_NULLPTR); ~HUD_Scene(); void set_data_for_widget1(double value); double get_data_for_widget1(); void set_data_for_widget2(double value); double get_data_for_widget2(); private: QGraphicsView* hud_view; QGraphicsProxyWidget* hud_widget1_symbology; QWidget* hud_widget1; QGraphicsProxyWidget* hud_widget2_symbology; QWidget* hud_widget2; QTimer* hud_test_timer; double data_for_widget1; double data_for_widget2; private slots: void test_hud(); }; #endif //Source File #include <QtWidgets/QWidget> #include <QtWidgets/QDialog> #include <QtWidgets/QGraphicsView> #include <QtWidgets/QGraphicsProxyWidget> #include <QtCore/QTimer> #include "hud_symbology1.hpp" #include "hud_symbology2.hpp" HUD_Scene::HUD_Scene(QObject* parent) :QGraphicsScene(parent) { data_for_widget1=0.0; data_for_widget2=0.0; /////////////////////////////////////////////////////////////////////////////// this->setSceneRect(0,0,1120,840); hud_view = new QGraphicsView(this); hud_view->resize/*setFixedSize*/(1120,840); hud_view->setSceneRect(0, 0, 1118, 838); hud_view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); hud_view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); hud_view->setFrameStyle(54); hud_widget1 = new HUD_Symbology1(); hud_widget1_symbology = this->addWidget(hud_widget1); hud_widget1_symbology = this->setPos(0, 294); hud_widget2= new HUD_Symbology2(); hud_widget2_symbology = this->addWidget(hud_widget2); hud_widget2_symbology = this->setPos(0, 394); hud_view->setWindowFlags(hud_view->windowFlags() | Qt::WindowStaysOnTopHint); hud_view->setStyleSheet("background:transparent"); hud_view->setAttribute(Qt::WA_TranslucentBackground); hud_view->setWindowFlag(Qt::FramelessWindowHint); hud_view->show(); /////////////////////////////////////////////////////////////////////////////// hud_test_timer = new QTimer(this); QObject::connect(hud_test_timer, SIGNAL(timeout()), this, SLOT(test_hud())); hud_test_timer->setInterval(20); hud_test_timer->start(); /////////////////////////////////////////////////////////////////////////////// } HUD_Scene::~HUD_Scene() { } void HUD_Scene::set_data_for_widget1(double value) { air_speed = speed_value; dynamic_cast<HUD_Symbology1*>(hud_widget1)->set_data(value); } double HUD_Scene::get_data_for_widget1() { return data_for_widget1; } void HUD_Scene::set_data_for_widget2(double value) { data_for_widget2 = value; dynamic_cast<HUD_Symbology2*>(hud_widget2)->set_data(value); } double HUD_Scene::get_data_for_widget2() { return data_for_widget2; } void HUD_Scene::test_hud() { // this function is for testing /////////////////////////////////////////////////////////////////////////////// data_for_widget1 += 0.01; set_data_for_widget1(data_for_widget1 ); /////////////////////////////////////////////////////////////////////////////// data_for_widget2 += 0.01; set_data_for_widget2(data_for_widget1 ); /////////////////////////////////////////////////////////////////////////////// }
How can i solve this overlapping problem?
-
@AdemMetinCALI said in Image Overlap Problem in QGraphicsScene:
How can i solve this overlapping problem?
How do you want to solve it? In which way? Behavior?!
Avoid overlapping? Only show the arrow-shaped objects and hide the scale, when they overlap? -
@AdemMetinCALI It would be interesting to tell us what is the result you expect to have. You can create it with any image editor (Gimp, Photoshop, MSPaint, ...).
So we could tell you how to achieve it! -
@Pl45m4 I added the tapes as pictures and move them according to the value. I want to see only the values inside the rectanges.
-
@KroMignon i want to see the values inside rectangles, not the value and fragments of tape. I gave you a simple example of my structure in order to informed you.