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. How to fetch coordinates of a Widget in QDockWidget?
QtWS25 Last Chance

How to fetch coordinates of a Widget in QDockWidget?

Scheduled Pinned Locked Moved Solved General and Desktop
qt5guiuser interfacec++ qt
5 Posts 2 Posters 929 Views
  • 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.
  • R Offline
    R Offline
    rohit1729
    wrote on last edited by
    #1

    I am trying to fetch coordinates of Visualization Panel B in QDockWidget (Panel A) by creating a QLabel.
    alt text
    On hovering of mouse in Panel B, respective coordinates should display in Panel A. I've separate cpp files for both the panels. Panel A class contains QDockWidget and QLabel and Panel B class has Visualization Widget. Panel B class has mouseMoveEvent() defined in it.
    Let's say Panel B class has below code:

    void panelB::mouseMoveEvent(QMouseEvent *eventMove)
    {
        QString txt;
        txt = QString("(X:%1,Y:%2)").arg(eventMove->pos().x()).arg(eventMove->pos().y());
        //qDebug() << txt;
    }
    

    Let's say Panel A class has below code:

    QWidget *panelA::getData(QString name)
    {
        QGroupBox *data = new QGroupBox;
        data->setTitle("Mouse Coordinates");
    
        QLabel *x_y = new QLabel(data);
        x_y->setGeometry(QRect(110,20,100,20));
        //x_y->setText(txt);
    }
    

    How do I configure both the functions with the current structure to display the coordinates in Panel A. I've checked with qDebug() and it's working fine. Also how difficult is to change the current coordinate systems?

    jsulmJ 1 Reply Last reply
    0
    • R rohit1729

      I am trying to fetch coordinates of Visualization Panel B in QDockWidget (Panel A) by creating a QLabel.
      alt text
      On hovering of mouse in Panel B, respective coordinates should display in Panel A. I've separate cpp files for both the panels. Panel A class contains QDockWidget and QLabel and Panel B class has Visualization Widget. Panel B class has mouseMoveEvent() defined in it.
      Let's say Panel B class has below code:

      void panelB::mouseMoveEvent(QMouseEvent *eventMove)
      {
          QString txt;
          txt = QString("(X:%1,Y:%2)").arg(eventMove->pos().x()).arg(eventMove->pos().y());
          //qDebug() << txt;
      }
      

      Let's say Panel A class has below code:

      QWidget *panelA::getData(QString name)
      {
          QGroupBox *data = new QGroupBox;
          data->setTitle("Mouse Coordinates");
      
          QLabel *x_y = new QLabel(data);
          x_y->setGeometry(QRect(110,20,100,20));
          //x_y->setText(txt);
      }
      

      How do I configure both the functions with the current structure to display the coordinates in Panel A. I've checked with qDebug() and it's working fine. Also how difficult is to change the current coordinate systems?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @rohit1729 Emit a signal in panelB::mouseMoveEvent with the coordinates as parameters and connect a slot to this signal in panelA.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      R 1 Reply Last reply
      1
      • jsulmJ jsulm

        @rohit1729 Emit a signal in panelB::mouseMoveEvent with the coordinates as parameters and connect a slot to this signal in panelA.

        R Offline
        R Offline
        rohit1729
        wrote on last edited by
        #3

        @jsulm Since I'm new, Can you provide the pseudo code to do the same ?

        jsulmJ 1 Reply Last reply
        0
        • R rohit1729

          @jsulm Since I'm new, Can you provide the pseudo code to do the same ?

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by jsulm
          #4

          @rohit1729 You should read this first: https://doc.qt.io/qt-5/signalsandslots.html

          void panelB::mouseMoveEvent(QMouseEvent *eventMove)
          {
              QString txt;
              txt = QString("(X:%1,Y:%2)").arg(eventMove->pos().x()).arg(eventMove->pos().y());
              emit coordinatesChanged(eventMove->pos().x(), eventMove->pos().y());
              //qDebug() << txt;
          }
          

          coordinatesChanged would be the signal.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          R 1 Reply Last reply
          1
          • jsulmJ jsulm

            @rohit1729 You should read this first: https://doc.qt.io/qt-5/signalsandslots.html

            void panelB::mouseMoveEvent(QMouseEvent *eventMove)
            {
                QString txt;
                txt = QString("(X:%1,Y:%2)").arg(eventMove->pos().x()).arg(eventMove->pos().y());
                emit coordinatesChanged(eventMove->pos().x(), eventMove->pos().y());
                //qDebug() << txt;
            }
            

            coordinatesChanged would be the signal.

            R Offline
            R Offline
            rohit1729
            wrote on last edited by
            #5
            This post is deleted!
            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