Results 1 to 7 of 7

Thread: signals for key presses ?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2009
    Posts
    11
    Qt products
    Qt4
    Platforms
    Windows

    Unhappy 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 ?

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default 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.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3
    Join Date
    Jun 2009
    Posts
    11
    Qt products
    Qt4
    Platforms
    Windows

    Unhappy Re: signals for key presses ?

    Thank you,this solution is based on inheriting QObject, but i don't want to use inheritance.

  4. #4
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: signals for key presses ?

    what do you want to achive? give us more information.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  5. #5
    Join Date
    Jun 2009
    Posts
    11
    Qt products
    Qt4
    Platforms
    Windows

    Post Re: signals for key presses ?

    here is the code:

    Qt Code:
    1. int main(int argc,char** args)
    2. {
    3. QApplication a(argc, argv);
    4. QSplitter* splitter = new QSplitter();
    5.  
    6. QDirModel* model = new QDirModel();
    7. QTreeView* tree = new QTreeView(splitter);
    8. tree->setModel(model);
    9. tree->setRootIndex( model->index( QDir::currentPath() ) );
    10.  
    11. QListView* lview = new QListView(splitter);
    12. lview->setModel(model);
    13. lview->setRootIndex( model->index(QDir::currentPath()) );
    14.  
    15. QStringList* stringList = new QStringList( QString("item 0") );
    16. for (int i = 1;i<10;i++)
    17. stringList->append( QString("item %1").arg(i) );
    18.  
    19. StringListModel* myCustomModel = new StringListModel(*stringList);
    20. QTreeView* view3 = new QTreeView(splitter);
    21. view3->setModel(myCustomModel);
    22.  
    23. splitter->show();
    24.  
    25. return a.exec();
    26. }
    To copy to clipboard, switch view to plain text mode 


    as i press enter i want to add new string to stringList and reflect the changes to the view.
    Last edited by wysota; 9th June 2009 at 10:34. Reason: missing [code] tags

  6. #6
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default 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.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  7. #7
    Join Date
    Jun 2009
    Posts
    11
    Qt products
    Qt4
    Platforms
    Windows

    Smile Re: signals for key presses ?

    Yes i tried it and it works, thank you.

Similar Threads

  1. QStateMachine and signals
    By rossm in forum Qt Programming
    Replies: 2
    Last Post: 26th March 2009, 10:43
  2. Signals are delayed on X11?
    By Cruz in forum Qt Programming
    Replies: 13
    Last Post: 18th February 2009, 12:59
  3. Signals and Slots
    By 83.manish in forum Qt Programming
    Replies: 3
    Last Post: 30th June 2008, 10:31
  4. QThread and signals (linux/UNIX signals not Qt Signals)
    By Micawber in forum Qt Programming
    Replies: 1
    Last Post: 28th November 2007, 22:18
  5. KDE Signals
    By chombium in forum KDE Forum
    Replies: 1
    Last Post: 25th January 2006, 18:45

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.