PDA

View Full Version : Question about focus



franco.amato
21st January 2010, 16:41
Hi,
I have a doubt regarding focus. Maybe this is not a Qt related topic, if so sorry in advance.
I have a Widget inherited from QWidget having some children ( push buttons and other widgets ).
So:


class WaveWidget : public QWidget
{
Q_OBJECT

public:
WaveWidget( QWidget* parent = 0 );
virtual ~WaveWidget();

void setSoundFile( QString soundName_ );
void closeSoundFile( QString soundName_ );

public slots:
void playSound();
void stopSound();
void zoomIn();
void zoomOut();
void setZoomFactor( float f );

signals:
void zoomFactorChanged( float );

protected:
virtual void focusInEvent( QFocusEvent * );
virtual void focusOutEvent( QFocusEvent * );
virtual void keyPressEvent( QKeyEvent* event );

private:
WaveDisplay* m_WaveDisplay;
PanelInfo* m_panel;

SoundData* m_wave;

QPushButton* button1;
QPushButton* button2;
QPushButton* button3;
QPushButton* button4;
QPushButton* button5;
QPushButton* button6;
QPushButton* button7;
QPushButton* button8;
QPushButton* button9;
QPushButton* button10;
QPushButton* m_zoomInBtn;
QPushButton* m_zoomOutBtn;

QLabel* m_titleLabel;

QLed* m_statusLed;

float m_ZoomFactor;
};

The WaveWidget should react to keyboard keys pressed ( I reimplemented keyPressEvent ).
If initially WaveWidget has focus, pressing tab the focus pass to it's children. In this case WaveWidges still react to keyboard keypressed?
I would like yes, but I don't know how to implement such behaviour.

Best Regards

psih128
22nd January 2010, 08:08
You can install an event handler to catch the key events of the child widgets of your WaveWidget. This is what comes first on my mind. There might be an easier solution though...

void QObject::installEventFilter ( QObject * filterObj )
You will find more in the documentation.

franco.amato
22nd January 2010, 17:46
You can install an event handler to catch the key events of the child widgets of your WaveWidget. This is what comes first on my mind. There might be an easier solution though...

You will find more in the documentation.

Hi thank you very much for your mail.
I try to explain what I would implement ( hoping my poor english help me ).
In my mainapplication I have a centralwidget cw.
cw contains 2 wavewidget widgets ww
so:
cw
|____ww1
|____ww2

every ww contains many widgets ( buttons and other.. see class WaveWidget description above - previous post - )

I would implement this behaviour:
User with tab ( or another key ) switch focus between ww1 and ww2 whitout passing for all children of every ww.
For example focus is in ww1 -> user click tab -> focus on ww2 -> user click tab -> focus on ww1 -> so on...

Is possible? I have no idea on how implement it.

Best Regards,
Franco