Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Link QAction availability to user selection
Qt 6.12 LTS is out! See what's new in the release blog

Link QAction availability to user selection

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 2 Posters 1.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.
  • T Offline
    T Offline
    theo_ld
    wrote on last edited by
    #1

    Hello everyone,

    I've created some QActions into QMenus, I'd like to disable them if no selection is done in my main widget.
    How can I do it ?

    I'm aware of the QAction->setEnabled() method, but how can I link it to the user mouse selection ?

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

      Hi,

      What kind of selection are you referring to ?

      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
      • T Offline
        T Offline
        theo_ld
        wrote on last edited by
        #3

        It's a user left-click selection of a QItemSelectionModel on a QTableView. The user data is stored into a QTableModel.

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

          Then add a slot to the class that manages these actions and connect it to the selectionChanged signal of your selection model. In there check whether the selection is empty and update the action state accordingly.

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

          T 1 Reply Last reply
          1
          • T Offline
            T Offline
            theo_ld
            wrote on last edited by
            #5

            I try that, thanks for you advice !

            1 Reply Last reply
            0
            • SGaistS SGaist

              Then add a slot to the class that manages these actions and connect it to the selectionChanged signal of your selection model. In there check whether the selection is empty and update the action state accordingly.

              T Offline
              T Offline
              theo_ld
              wrote on last edited by theo_ld
              #6

              @SGaist I tried this, but the selectionChanged signal doesn't exist in the QAction class.

                  connect(callAct, &QItemSelectionModel::selectionChanged, ipWidget, &IpWidget::onSelectionChanged);
              
              
              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Because it's a signal of QTableView.

                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
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt
                • Unsolved