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. Image Overlap Problem in QGraphicsScene
Qt 6.11 is out! See what's new in the release blog

Image Overlap Problem in QGraphicsScene

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 1.1k 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.
  • AdemMetinCALIA Offline
    AdemMetinCALIA Offline
    AdemMetinCALI
    wrote on last edited by
    #1

    Hi,

    I try to develop a transparent hud. And i face an overlapping problem that can be seen from the image:

    HUD.PNG

    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?

    Pl45m4P 1 Reply Last reply
    0
    • AdemMetinCALIA AdemMetinCALI

      Hi,

      I try to develop a transparent hud. And i face an overlapping problem that can be seen from the image:

      HUD.PNG

      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?

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by Pl45m4
      #2

      @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?


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      AdemMetinCALIA 1 Reply Last reply
      0
      • KroMignonK Offline
        KroMignonK Offline
        KroMignon
        wrote on last edited by
        #3

        @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!

        It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

        AdemMetinCALIA 1 Reply Last reply
        0
        • Pl45m4P Pl45m4

          @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?

          AdemMetinCALIA Offline
          AdemMetinCALIA Offline
          AdemMetinCALI
          wrote on last edited by
          #4

          @Pl45m4 I added the tapes as pictures and move them according to the value. I want to see only the values inside the rectanges.

          1 Reply Last reply
          0
          • KroMignonK KroMignon

            @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!

            AdemMetinCALIA Offline
            AdemMetinCALIA Offline
            AdemMetinCALI
            wrote on last edited by
            #5

            @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.

            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