PDA

View Full Version : Make QDial ignore user input



burnchar
10th February 2010, 18:47
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.

caduel
10th February 2010, 20:15
setEnabled(false) ?

burnchar
17th February 2010, 17:46
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.

Lykurg
17th February 2010, 18:54
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!

Lykurg
17th February 2010, 19:52
I have had 5 minutes time...
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:
void mouseMoveEvent(QMouseEvent *e)
{
if(m_enable) QDial::mouseMoveEvent(e);
}
void mousePressEvent(QMouseEvent *e)
{
if(m_enable) QDial::mousePressEvent(e);
}
void mouseReleaseEvent(QMouseEvent *e)
{
if(m_enable) QDial::mouseReleaseEvent(e);
}
void keyPressEvent(QKeyEvent *e)
{
if(m_enable) QDial::keyPressEvent(e);
}
void keyReleaseEvent(QKeyEvent *e)
{
if(m_enable) QDial::keyReleaseEvent(e);
}
void wheelEvent(QWheelEvent *e)
{
if(m_enable) QDial::wheelEvent(e);
}

private:
bool m_enable;
};

Maybe there are other events you want to disable.


Lykurg