How can I get trigger signal for disabled QAction element?
Asked Answered
D

1

2

I have disabled QAction menu element:

QAction *item = new QAction(itemTitle);
item->setEnabled(false);

I use SLOT connection to call function after element was pressed, but it's works only for enabled elements:

QObject::connect(item, SIGNAL(triggered()), this, SLOT(func()));

My question is how can I trigger some function for disabled QAction element?

Qt 5.9.2, MSVC2017 64bit compiler

Dreda answered 16/10, 2017 at 9:32 Comment(0)
D
1

setEnabled() property holds whether the widget is enabled.

In general an enabled widget handles keyboard and mouse events; a disabled widget does not. An exception is made with QAbstractButton.

When a widget is disable, all mouse and keyboard events are also disable.

More info : http://doc.qt.io/qt-4.8/qwidget.html#enabled-prop

Dratted answered 16/10, 2017 at 9:52 Comment(5)
so there is no way to do that? what if somehow simulate disabled QAction element with QT stylesheet, but not with setEnabled() itself, is this way is possible?Dreda
CSS disable is the same. maybe you could change backcolor, border, reimplement events to kinda simulate disable. other wise not possible.Dratted
I suggest you to find another way, why you need to trigger disabled widget?Dratted
The idea is that I have some list of filenames and if file is not downloaded it is displaying as disabled. If use click on disabled element, the file begins to download. Generally, downloaded files are active in menu, undownloaded are disabled.Dreda
It's kinda your opinion to how to simulate a disable button. maybe this help you. QColor color = ui->btnDisable->palette().button().color(); and ui->btnEnable->setStyleSheet("background-color:" + color.name() +";");Dratted

© 2022 - 2024 — McMap. All rights reserved.