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. I want to change the QAction::setenabled() to true after left a QContextMenu in QTreeView
Forum Updated to NodeBB v4.3 + New Features

I want to change the QAction::setenabled() to true after left a QContextMenu in QTreeView

Scheduled Pinned Locked Moved Unsolved General and Desktop
18 Posts 3 Posters 809 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.
  • D Offline
    D Offline
    developer_61
    wrote on last edited by developer_61
    #1

    Hello !
    I have following problem:
    So first of all I'm setting an QAction in the constructor to false:

      ui->exampleAction->setEnabled(false);
    

    So if i'm going to right click an element in the QTreeView the QContextMenu open and set the Action to true like:

      ui->exampleAction->setEnabled(true);
    

    So what i want is to reset the action again to false after i left the QContextMenu. How can i achive that?
    The problem is that i'm setting the action to false in the constructor.

    Regards

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

      Hi,

      How are you handling your contextual menu ?

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

        @SGaist hi,
        like that:
        constructor:

        ui->tree->setContextMenuPolicy(Qt::CustomContextMenu);
        connect(ui->tree, SIGNAL(customContextMenuRequested(const QPoint&)), SLOT(showContextMenu(const QPoint&))); 
        

        function:

        void MainWindow::showContextMenu(const QPoint& pos)
        {
        
          auto contextMenu = new QMenu(ui->tree);
          contextMenu->addAction("Uninstall TA", this, SLOT(()));
        
        ui->example>setEnabled(true);
        
          QModelIndex index = ui->tree->indexAt(pos);
          if (index.isValid() && index.row() % 2 == 0) {
            contextMenu->exec(ui->tree->viewport()->mapToGlobal(pos));
          }
        }
        

        so what i want is, after i left this sequence here or in another words i close the menu i want to set the action again to false

        1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @developer_61 said in I want to change the QAction::setenabled() to true after left a QContextMenu in QTreeView:

          words i close the menu

          Why can't you simply enable it efter the exec() call then?

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          D 1 Reply Last reply
          2
          • Christian EhrlicherC Christian Ehrlicher

            @developer_61 said in I want to change the QAction::setenabled() to true after left a QContextMenu in QTreeView:

            words i close the menu

            Why can't you simply enable it efter the exec() call then?

            D Offline
            D Offline
            developer_61
            wrote on last edited by developer_61
            #5

            @Christian-Ehrlicher
            And Then? If im going to set the Action in showContextMenu to True and After exec again to false i will only See the false. Sorry i correct My Comment.

            1 Reply Last reply
            0
            • Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              I don't understand what you want - if you want an action be enabled then set it to enabled, if not then set it to not enabled. Once the menu is shown it will use the current state of the action to display the menu.

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              1 Reply Last reply
              0
              • D Offline
                D Offline
                developer_61
                wrote on last edited by developer_61
                #7

                I want to have the Action not enabled in the First Step like i did in the constructor. After that i want to set the Action enabled After i‘m Open the Context Menu with the Right Click. In the Last Step i want to set it not enabled after i‘m going to Close the context menu. Why?
                I have More actions with More elements. The elements will have another enabled Actions.
                @Christian-Ehrlicher that is want i want to reach.

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

                  And where is that enabled action shown in your application when you trigger your contextual menu ?

                  By the way, you never delete contextMenu so it will fill up memory until ui->tree is deleted.

                  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
                  • D Offline
                    D Offline
                    developer_61
                    wrote on last edited by developer_61
                    #9

                    @SGaist the Activated Action will be selectable in my
                    contextmenu. So After the Right Click I can select it.
                    ->it will shown in the Context Menu.

                    So what you mean? Is there no Chance to realize that what i want ?

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

                      You do realize that from your code you are changing two different unrelated actions ?

                      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
                      • D Offline
                        D Offline
                        developer_61
                        wrote on last edited by developer_61
                        #11

                        @SGaist Yeah sorry ist has to be the Same Action.

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

                          Then why use two different actions ?

                          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
                          • D Offline
                            D Offline
                            developer_61
                            wrote on last edited by developer_61
                            #13

                            @SGaist what you mean? I mean i Need the same
                            Action to set enabled and Set not enabled?

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

                              You are explaining that you want an action to be enabled when showing your context menu and disabled afterward. Is that the action that should be shown by the contextual menu ?

                              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
                              • D Offline
                                D Offline
                                developer_61
                                wrote on last edited by
                                #15

                                @SGaist yess right its exactly that Action.

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

                                  Then use that action in your contextual menu.

                                  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
                                  • D Offline
                                    D Offline
                                    developer_61
                                    wrote on last edited by developer_61
                                    #17

                                    @SGaist and then how can i set it to not enabled After i close the Context Menu?

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

                                      Exactly like you were already explained: do that after the exec call.

                                      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

                                      • Login

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