Make QDial ignore user input
I'd appreciate suggestions on an elegant, simple way to make QDials ignore user input but accept programmatic input.
I could make a new class derived from QDial and override several event handlers, but I am curious if I missed some obvious 1-liner or similar.
Re: Make QDial ignore user input
Re: Make QDial ignore user input
Thank you for the reply. Unfortunately, disabling the control makes it ignore all programmatic input until it is re-enabled. I'd still like to be able to set its position by calling its set functions.
Re: Make QDial ignore user input
I haven't tried, but following should work:- Subclass QDial
- add a custom slot where you set a privat bool (acceptUserInput)
- reimp mouse***event, there redirect the event to the base class only if acceptUserInput is true
Should work and in done in < 5 minutes!
Re: Make QDial ignore user input
I have had 5 minutes time...
Code:
class MyDial
: public QDial{
public:
explicit MyDial
(QWidget *parent
= 0) : QDial(parent
), m_enable
(true) {} void setUserInputEnabled(bool enable)
{
m_enable = enable;
setFocusPolicy(m_enable ? Qt::WheelFocus : Qt::NoFocus);
}
protected:
{
if(m_enable
) QDial::mouseMoveEvent(e
);
}
{
if(m_enable
) QDial::mousePressEvent(e
);
}
{
if(m_enable
) QDial::mouseReleaseEvent(e
);
}
{
if(m_enable
) QDial::keyPressEvent(e
);
}
{
if(m_enable
) QDial::keyReleaseEvent(e
);
}
{
if(m_enable
) QDial::wheelEvent(e
);
}
private:
bool m_enable;
};
Maybe there are other events you want to disable.
Lykurg