signals for key presses ?
i have a QWidget object and want to add handlers for some key presses, the traditional way
is to inherit QWidget and reimplement the virtual funcitons, my question is: can i add
event handlers without inheriting QWidget ?
is there signals for keyboard events ?:confused:
Re: signals for key presses ?
you can set event filter on you widget and process QKeyEvent.
take a look at QObject::installEventFilter and QObject::eventFilter.
Re: signals for key presses ?
Thank you,this solution is based on inheriting QObject, but i don't want to use inheritance.
Re: signals for key presses ?
what do you want to achive? give us more information.
Re: signals for key presses ?
here is the code:
Code:
int main(int argc,char** args)
{
tree->setModel(model);
tree
->setRootIndex
( model
->index
( QDir::currentPath() ) );
lview->setModel(model);
lview
->setRootIndex
( model
->index
(QDir::currentPath()) );
for (int i = 1;i<10;i++)
stringList
->append
( QString("item %1").
arg(i
) );
StringListModel* myCustomModel = new StringListModel(*stringList);
view3->setModel(myCustomModel);
splitter->show();
return a.exec();
}
as i press enter i want to add new string to stringList and reflect the changes to the view.
Re: signals for key presses ?
I don't see a problem. create a new widget and put your splitter on it, then install event filter on needed widget and process key event.
Re: signals for key presses ?
Yes i tried it and it works, thank you. :)