Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. How identify what Widget is activated?
Forum Updated to NodeBB v4.3 + New Features

How identify what Widget is activated?

Scheduled Pinned Locked Moved Solved Qt Creator and other tools
6 Posts 3 Posters 2.9k 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.
  • B Offline
    B Offline
    bozo6919
    wrote on last edited by
    #1

    I have for beginning one widget like this :
    0_1531391786498_QMainWindow.png
    The window in yellow is a widget. When I click on a button, one signal is send and I go in a function for split this widget and obtain this :
    0_1531392014979_Capture.PNG
    We can see that another widget has been added at the window (and the arrow is the split).
    This function to obtain that is :

        QWidget *first = MainWindow::first;
        QWidget *second = createContentPanel();
        QSplitter *split = new QSplitter;
    
        split->addWidget(first);
        split->addWidget(second);
        delete layout;
        layout = new QVBoxLayout;
        layout->addWidget(split);
        widget->setLayout(layout);
    

    What I want, it's replace "first = MainWindow::first;" by another way to search the QWidget first.
    This code has to work for more widget and "first" have to be equal at the QWidget selected (clicked or with the mouse on the widget.)

    Someone know how we can identify what widget is activated?

    Sorry for my English ^^'

    1 Reply Last reply
    0
    • JonBJ JonB

      @bozo6919

      I would like to have a function that return a QWidget where is my mouse.

      If nobody offers you a better way, you could walk all your widgets (http://doc.qt.io/qt-5/qapplication.html#allWidgets) and use http://doc.qt.io/qt-5/qwidget.html#underMouse to determine which widget the mouse is over.

      Previously clicked is another matter.

      If you just want the widget with current focus that's much easier.

      If that's really what you are looking for. Depending on what you are going to use this information to achieve, there may be better ways to approach it.

      B Offline
      B Offline
      bozo6919
      wrote on last edited by
      #6

      @JonB Thanks for your answer.
      So, I stock now one QWidgets in a class named ContentPanel and I stock all theses ContentPanel in a QVector.
      At all ContentPanel, I apply this function :

      bool ContentPanel::event(QEvent *event)
      {
          if (event->type() == QEvent::Enter)
              focus = true;
          else if (event->type() == QEvent::Leave)
              focus = false;
          return (QWidget::event(event));
      }
      

      I have just to look for the variable focus on my class ContentPanel who refer to a QWidget.

      Thanks :)

      Sorry for my English ^^'

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Hi,

        Do you mean you want to keep a pointer on the widget that has the focus ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        B 1 Reply Last reply
        1
        • SGaistS SGaist

          Hi,

          Do you mean you want to keep a pointer on the widget that has the focus ?

          B Offline
          B Offline
          bozo6919
          wrote on last edited by
          #3

          @SGaist
          I would like to have a function that return a QWidget where is my mouse.
          Is it possible ?

          Sorry for my English ^^'

          JonBJ 1 Reply Last reply
          0
          • B bozo6919

            @SGaist
            I would like to have a function that return a QWidget where is my mouse.
            Is it possible ?

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #4

            @bozo6919

            I would like to have a function that return a QWidget where is my mouse.

            If nobody offers you a better way, you could walk all your widgets (http://doc.qt.io/qt-5/qapplication.html#allWidgets) and use http://doc.qt.io/qt-5/qwidget.html#underMouse to determine which widget the mouse is over.

            Previously clicked is another matter.

            If you just want the widget with current focus that's much easier.

            If that's really what you are looking for. Depending on what you are going to use this information to achieve, there may be better ways to approach it.

            B 1 Reply Last reply
            1
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #5

              You could have an event filter that would look for the focus related events.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              1
              • JonBJ JonB

                @bozo6919

                I would like to have a function that return a QWidget where is my mouse.

                If nobody offers you a better way, you could walk all your widgets (http://doc.qt.io/qt-5/qapplication.html#allWidgets) and use http://doc.qt.io/qt-5/qwidget.html#underMouse to determine which widget the mouse is over.

                Previously clicked is another matter.

                If you just want the widget with current focus that's much easier.

                If that's really what you are looking for. Depending on what you are going to use this information to achieve, there may be better ways to approach it.

                B Offline
                B Offline
                bozo6919
                wrote on last edited by
                #6

                @JonB Thanks for your answer.
                So, I stock now one QWidgets in a class named ContentPanel and I stock all theses ContentPanel in a QVector.
                At all ContentPanel, I apply this function :

                bool ContentPanel::event(QEvent *event)
                {
                    if (event->type() == QEvent::Enter)
                        focus = true;
                    else if (event->type() == QEvent::Leave)
                        focus = false;
                    return (QWidget::event(event));
                }
                

                I have just to look for the variable focus on my class ContentPanel who refer to a QWidget.

                Thanks :)

                Sorry for my English ^^'

                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