Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Qt Academy Launch in California!

    Solved How to fetch coordinates of a Widget in QDockWidget?

    General and Desktop
    qt5 gui user interface c++ qt
    2
    5
    457
    Loading More Posts
    • 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
      rohit1729 last edited by

      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?

      jsulm 1 Reply Last reply Reply Quote 0
      • jsulm
        jsulm Lifetime Qt Champion @rohit1729 last edited by

        @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 Reply Quote 1
        • R
          rohit1729 @jsulm last edited by

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

          jsulm 1 Reply Last reply Reply Quote 0
          • jsulm
            jsulm Lifetime Qt Champion @rohit1729 last edited by 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.

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

            R 1 Reply Last reply Reply Quote 1
            • R
              rohit1729 @jsulm last edited by

              This post is deleted!
              1 Reply Last reply Reply Quote 0
              • First post
                Last post