QWidget, setEnable, change not visible immediately
-
wrote on 28 Jan 2022, 09:21 last edited by SPlatten
In my application I have logic that enables or disables buttons based on conditions, I emit a signal to notify the button to change state and using the debugger I can see that when the signal is emitted the slot is called and the setEnabled function called.
If the application is left to run the visible appearance of the button does not change to reflect the state change, however if I more the context / focus from the effected window to another window in the same application the button isn't changes to show the change in state.
What could be the cause of this and how should I fix it, this is the slot that enable and disables the button:
void clsXMLnode::APIstate(bool blnState) { QWidget* pobjWidget(pobjGetWidget()); if ( pobjWidget == nullptr ) { //No widget, do nothing return; } pobjWidget->setEnabled(blnState); }
-
@SPlatten said in QWidget, setEnable, change not visible immediately:
Could it be that I need to change the connection type as presently its using the default ?
it shouldn't make a difference, or is this somehow across threads ?
try calling update() or repaint() on the button widget, after changing the enabled state.
It should do that automatically but, see if that helps!
wrote on 28 Jan 2022, 10:49 last edited by@J-Hilk , sorry for wasting your time....I've found the problem which as an error in my code.
-
In my application I have logic that enables or disables buttons based on conditions, I emit a signal to notify the button to change state and using the debugger I can see that when the signal is emitted the slot is called and the setEnabled function called.
If the application is left to run the visible appearance of the button does not change to reflect the state change, however if I more the context / focus from the effected window to another window in the same application the button isn't changes to show the change in state.
What could be the cause of this and how should I fix it, this is the slot that enable and disables the button:
void clsXMLnode::APIstate(bool blnState) { QWidget* pobjWidget(pobjGetWidget()); if ( pobjWidget == nullptr ) { //No widget, do nothing return; } pobjWidget->setEnabled(blnState); }
@SPlatten there may be some typos or mistakes in this:
however if I more the context / focus from the effected window to another window in the same application the button isn't changes to show the change in state
but I'm unable to decipher what is actually happening. Can you elaborate more?
-
@SPlatten there may be some typos or mistakes in this:
however if I more the context / focus from the effected window to another window in the same application the button isn't changes to show the change in state
but I'm unable to decipher what is actually happening. Can you elaborate more?
wrote on 28 Jan 2022, 09:34 last edited by@J-Hilk , A window is displayed with widgets, I have a number of buttons at the bottom of the window, the state of these buttons is defined by editing the widgets.
If a QLineEdit widget is modified then one of the buttons at the bottom is enabled by emitting a signal. As stated in my post I can see that the slot is called and the correct widget ( button ) is being set to the correct state which is passed into the slot.
The problem is that the button's visible state does not change from disabled to enabled unless I change the window focus to another window, then the button visible state changes.
-
@J-Hilk , A window is displayed with widgets, I have a number of buttons at the bottom of the window, the state of these buttons is defined by editing the widgets.
If a QLineEdit widget is modified then one of the buttons at the bottom is enabled by emitting a signal. As stated in my post I can see that the slot is called and the correct widget ( button ) is being set to the correct state which is passed into the slot.
The problem is that the button's visible state does not change from disabled to enabled unless I change the window focus to another window, then the button visible state changes.
@SPlatten alright
what version of Qt are you using, and to you have custom stylesheets on them and/or have you overwritten their paintEvent ?
-
@SPlatten alright
what version of Qt are you using, and to you have custom stylesheets on them and/or have you overwritten their paintEvent ?
wrote on 28 Jan 2022, 09:51 last edited by SPlatten@J-Hilk Qt 5.15.2, no custom style sheets. The buttons are based on QPushButton:
class clsQtPushBtn : public QPushButton, public clsXMLinterface { Q_OBJECT private: static mpSignals mscmpSignals; QMetaObject::Connection connect(clsSignal* pobjSignal); private slots: void rptrClicked(bool blnChecked); void rptrPressed(); void rptrReleased(); void rptrToggled(bool blnChecked); public: static const char mscszQtSignalClicked[]; static const char mscszQtSignalPressed[]; static const char mscszQtSignalReleased[]; static const char mscszQtSignalToggled[]; static const char mscszStyleBorderBottomLeftRadius[]; static const char mscszStyleBorderBottomRightRadius[]; static const char mscszStyleBorderTopLeftRadius[]; static const char mscszStyleBorderTopRightRadius[]; explicit clsQtPushBtn(clsXMLnode* pobjNode, QString* pstrCSS , QWidget* parent = nullptr); static bool blnValidSignal(QString strSignal); static mpSignals* pmpGetSignals() { return &clsQtPushBtn::mscmpSignals; } signals: public slots: };
-
@SPlatten alright
what version of Qt are you using, and to you have custom stylesheets on them and/or have you overwritten their paintEvent ?
wrote on 28 Jan 2022, 10:24 last edited by@J-Hilk Could it be that I need to change the connection type as presently its using the default ?
QObject::connect(pobjWindow, &clsXMLnode::APInotifyUndoChanges ,pobjNode, &clsXMLnode::APIstate);
-
@J-Hilk Could it be that I need to change the connection type as presently its using the default ?
QObject::connect(pobjWindow, &clsXMLnode::APInotifyUndoChanges ,pobjNode, &clsXMLnode::APIstate);
@SPlatten said in QWidget, setEnable, change not visible immediately:
Could it be that I need to change the connection type as presently its using the default ?
it shouldn't make a difference, or is this somehow across threads ?
try calling update() or repaint() on the button widget, after changing the enabled state.
It should do that automatically but, see if that helps!
-
@SPlatten alright
what version of Qt are you using, and to you have custom stylesheets on them and/or have you overwritten their paintEvent ?
wrote on 28 Jan 2022, 10:38 last edited by@J-Hilk , looking at this again in the debugger, I can now see that the slot is not actually being called until I change the focus, yet the signal is being emitted instantly.
Does that help shed any light on why the slot isn't being called when the signal is emitted ?
-
@SPlatten said in QWidget, setEnable, change not visible immediately:
Could it be that I need to change the connection type as presently its using the default ?
it shouldn't make a difference, or is this somehow across threads ?
try calling update() or repaint() on the button widget, after changing the enabled state.
It should do that automatically but, see if that helps!
wrote on 28 Jan 2022, 10:49 last edited by@J-Hilk , sorry for wasting your time....I've found the problem which as an error in my code.
1/9