I want to change the QAction::setenabled() to true after left a QContextMenu in QTreeView
-
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
-
Hi,
How are you handling your contextual menu ?
-
@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
-
@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?
-
@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. -
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.
-
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. -
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.
-
@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 ?
-
You do realize that from your code you are changing two different unrelated actions ?
-
@SGaist Yeah sorry ist has to be the Same Action.
-
Then why use two different actions ?
-
@SGaist what you mean? I mean i Need the same
Action to set enabled and Set not enabled? -
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 ?
-
@SGaist yess right its exactly that Action.
-
Then use that action in your contextual menu.
-
@SGaist and then how can i set it to not enabled After i close the Context Menu?
-
Exactly like you were already explained: do that after the exec call.