PDA

View Full Version : Problem with QT programming



keyurparekh
16th February 2011, 13:08
Hi all,

I need help very urgently.
I am trying to change push button geometry when i press tab key.

I have done it with mouse move event. so when mouse arrow is on push button it changes shape.

now i want that when i select push button using tab key it changes its shape.
I don't know how to do it.

Please help me in that matter. how can i do this. please send me code to perform this action.

Thanks in advance.

squidge
16th February 2011, 13:21
Have you tried installing an event listener?

keyurparekh
17th February 2011, 06:06
No i have try Key event.

this is in my1.cpp

void my1::keyPressEvent(QKeyEvent *event)
{
if (event->key() == Qt::Key_Tab)
{
pushButton->setGeometry(QRect(100, 110, 150, 101));
}
else
{
pushButton->setGeometry(QRect(100, 110, 140, 50));
}
}


in my1.h file i write

class my1 : public QWidget,private Ui_my1
{
Q_OBJECT

public:
explicit my1(QWidget *parent = 0, Qt::WindowFlags f = 0 );
~my1();

Protected:
void keyPressEvent(QKeyEvent * event);

};

but when i press tab key it does not change push button geometry. Please help me how to do this function.
Please if possible provide me code to implement this functionality.

thanks in advance... waiting for reply.........

nightghost
17th February 2011, 09:20
from C++ GUI Programming with Qt 4 page 164:


The Tab and Backtab (Shift+Tab) keys are special cases. They are handled by
QWidget::event() before it calls keyPressEvent(), with the semantic of passing
the focus to the next or previous widget in the focus chain.


Update: Also the online doc for QWidget::event() documents that.

squidge
17th February 2011, 13:19
keyPressEvent is insufficient (for the reason shown above). Install an event listener, as I've stated above.