c++ - Blocking signals on disabled widgets in Qt -
i have combo disabled, adding element emit currentindexchanged(int)
signal.
i expected signals naturally turned off when widget disabled, it's not case. know there blocksignals(bool)
, if there many widgets signals must "blocked when disabled", blocksignals
require boolean state each widget.
how can disable signals sent widget when disabled (and not alter blocksignals
state)?
edit clarify: since widget, user cannot interact when it's disabled, but signals emitted when altering widget programmatically. in case there 2 interesting signals: currentindexchanged(int)
, activated(int)
the problem in code alter combo programmatically , wish emit signal, , it's user alters combo interacting. that's why using currentindexchanged
, not activated
.
in both cases, anyway, don't want signals emitted when widget disabled.
the qcombobox
signals user interaction based end user point of view if have qcombobox
, nothing else question seems imply.
i cannot reproduce issue. have made short program cannot of qcombobox signals emitted since cannot interact widget.
edit: might idea upate question more context casual readers, based on further clarification in comments, yes, programatically might case, signals might useful process programmatically, too, corresponding slots, not major improvement if qt blocks them automatically.
luckily, feature wish have available:
bool qobject::blocksignals(bool block)
if block true, signals emitted object blocked (i.e., emitting signal not invoke connected it). if block false, no such blocking occur.
the return value previous value of signalsblocked().
note destroyed() signal emitted if signals object have been blocked.
if want many widgets, create simple function call instead of mywidget->setdisabled(true);
:
inline bool disableandblocksignals(qwidget *widget) { widget->setdisabled(true); return widget->blocksignals(true); }
if want disable of them, say, currentindexchanged
, can use disconnect manually then.
Comments
Post a Comment