Results 1 to 7 of 7

Thread: Shortcut override ?

  1. #1

    Default Shortcut override ?

    http://www.uploadgeek.com/share-DF3C_4BF8C763.html

    at a program like on the image, I want to make shorcut to skip forward or skip backward the video when I typing on the textEditor The key combinations I want : CTRL+Key_Left CTRL+Key_Right But these shortcuts are default shortcut on text editors. You can try when writing the post on this forum when you push CTRL+Key_Left it will go to the previous word, whatever. I want to deactive this shortcut on my texteditor and make the shortcuts to skip forward or backward for player. The shorcuts must be active when I typing on text editor and they must skip the video backward or forward.

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Shortcut override ?

    You can use QShortcut.
    But how do you now you're not in the text edit? By focus?
    How will that work? How will you set the focus on another object?

    Personally, I do not think this is a good idea.
    I prefer using a shortcut that isn't already used.

  3. #3

    Default Re: Shortcut override ?

    I already want that shortcuts work/active when I am in texteditor when typing! I do the shortcuts as ALT+A AND ALT+D when writing when I press ALT+A it works but when I do the shortcuts as CTRL+Key_Left and CTRL_Right it doesn't work it just goes to the next work or previous words( ctrl+key_left and ctrl+key_right are the shortcuts for these actions on any editor) the problem is I can't override them This a project and my theacher exactly wants CTRL+Key_Left and CTRL_Right to conrol the player it's ridicilious But I must do that.

    the text edit is the mainwindow and the player is created in it like

    Qt Code:
    1. TextEdit::TextEdit(QWidget *parent)
    2. : QMainWindow(parent)
    3. {...
    4.  
    5. MediaPlayer *player= new MediaPlayer(fileString, hasSmallScreen);
    6. QWidget* player2 =qobject_cast<MediaPlayer *>(player);
    7. QSplitter *splitter = new QSplitter(Qt::Horizontal);
    8. splitter->addWidget(player2);
    9. splitter->addWidget(textEdit);
    10.  
    11. ...
    12.  
    13. }
    To copy to clipboard, switch view to plain text mode 

    I try this

    Qt Code:
    1. TextEdit::TextEdit(QWidget *parent)
    2. : QMainWindow(parent){
    3. ...
    4. shortcuts[SH_SLIDER_DOWN] = new QShortcut(this);
    5. shortcuts[SH_SLIDER_DOWN]->setKey(QKeySequence(Qt::CTRL+Qt::Key_Left));
    6. shortcuts[SH_SLIDER_UP] = new QShortcut(this);
    7. shortcuts[SH_SLIDER_UP]->setKey(QKeySequence(Qt::ALT+Qt::Key_D));
    8. shortcuts[SH_PLAYORPAUSE] = new QShortcut(this);
    9. shortcuts[SH_PLAYORPAUSE]->setKey(QKeySequence(Qt::ALT+Qt::Key_W));
    10.  
    11. connect(shortcuts[SH_SLIDER_UP], SIGNAL(activated()), player, SLOT(stepForward()));
    12. connect(shortcuts[SH_SLIDER_DOWN], SIGNAL(activatedAmbiguously()), player, SLOT(stepBackward()));
    13. // I tried this too but nothing. connect(shortcuts[SH_SLIDER_DOWN], SIGNAL(activated()), player, SLOT(stepBackward()));
    14. connect(shortcuts[SH_PLAYORPAUSE], SIGNAL(activated()), player, SLOT(playPause()));
    15. ...
    16. }
    To copy to clipboard, switch view to plain text mode 

    But the CTRL+Key_Left just make the cursor posion previous word. I cant't override it.CTRL+Key_Left I think is a windows shortcut I don't know, it works in every where WORD, email or on this post
    Last edited by fenerista; 23rd May 2010 at 10:46.

  4. #4
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Shortcut override ?

    Subclass QTextEdit and reimplement void QTextEdit::keyPressEvent(QKeyEvent *e)
    Just pass all the key events except the ones you need for other purposes.

  5. #5

    Default Re: Shortcut override ?

    ok
    TextEdit is created like this class TextEdit : public QMainWindow. It contains QTextEdit class(and have this on TextEdit.h, QTextEdit *textEdit. You say this ? make a new class that inherits from Qtextedit and change its keypresseventfuntion.

    and change this QTextEdit *textEdit to QTextEdit *mytextEdit and do other changes on TextEdit constructor).


    But I don't know how I searched this and I tried it but I couldn't. Just I know I should call the orijinal funtion at the last of my keypressevet function.

    How cant I get ctrl+key_left

    Qt Code:
    1. void CodeEditor::keyPressEvent(QKeyEvent *event)
    2. {
    3. switch (event->key()) {
    4. case Qt::Key_Left: //1
    5. if (event->modifiers() & Qt::ControlModifier) {//2 , 1 and 2. line is it enougfor CTRL+ Key_Left ? or it doen't work for that I want.
    6. goToBeginningOfDocument();
    7. } else {
    8. goToBeginningOfLine();
    9. }
    10. break;
    11. case Qt::Key_End:
    12. ...
    13. default:
    14. QWidget::keyPressEvent(event);
    15. }
    16. }
    To copy to clipboard, switch view to plain text mode 

    I know it's for codeeditor but I can make the changes for textedit.
    Last edited by fenerista; 23rd May 2010 at 10:59.

  6. #6
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Shortcut override ?

    For the key sequences, check out http://doc.qt.nokia.com/4.6/qkeysequence.html

  7. #7

    Default Re: Shortcut override ?

    Qt Code:
    1. #ifndef MYTEXTEDIT_H
    2. #define MYTEXTEDIT_H
    3.  
    4. #include<QtGui>
    5.  
    6. class myTextEdit : public QTextEdit{
    7. Q_OBJECT
    8. public:
    9.  
    10. myTextEdit(QWidget *parent=0): QTextEdit(parent)
    11. {
    12. }
    13.  
    14. void keyPressEvent(QKeyEvent* e)
    15. {
    16. if(e->key()== Qt::Key_Left){
    17. if(e->modifiers()& Qt::ControlModifier)
    18. emit PushedCtrlL();
    19. else
    20. QTextEdit::keyPressEvent(e);
    21. }
    22. else
    23. QTextEdit::keyPressEvent(e);
    24. }
    25.  
    26. signals:
    27. void PushedCtrlL(void);
    28. };
    29.  
    30. #endif // MYTEXTEDIT_H
    To copy to clipboard, switch view to plain text mode 

    I did myText edit
    I overrided the keypressevent function
    and send a signal when CTRL+LEFT pushed

    Qt Code:
    1. TextEdit::TextEdit(QWidget *parent)
    2. : QMainWindow(parent)
    3. {
    4. ...
    5.  
    6.  
    7. connect(textEdit, SIGNAL(PushedCtrlL(void)),player, SLOT(stepBackward()));
    8. }
    To copy to clipboard, switch view to plain text mode 
    and it worked thx QT for signal and slot mechanism

    Just a little question

    Qt Code:
    1. if(e->key()== Qt::Key_Left){
    2. if(e->modifiers()& Qt::ControlModifier)
    To copy to clipboard, switch view to plain text mode 
    is there any better way for those two lines
    I don't know like
    Qt Code:
    1. if(e->key()==qkeysequence("CTRL+Keyleft")){
    2. emit PushedCtrlL();}
    To copy to clipboard, switch view to plain text mode 

    I am asking for that if I want ctrl+V+key_left for the stepbackward so what the two lines should be?

Similar Threads

  1. Cannot override copy shortcut
    By Paladin12 in forum Qt Programming
    Replies: 7
    Last Post: 19th April 2010, 14:56
  2. How to override system shortcut left Alt+Space
    By MasterBLB in forum Qt Programming
    Replies: 2
    Last Post: 28th March 2010, 11:28
  3. override shortcut icon in QToolBar
    By sudhansu in forum Qt Programming
    Replies: 1
    Last Post: 18th February 2010, 08:20
  4. Override a signal
    By daviddoria in forum Newbie
    Replies: 4
    Last Post: 9th February 2010, 18:18
  5. override the default cursor
    By lytfyre in forum Qt Programming
    Replies: 2
    Last Post: 8th December 2008, 20:00

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.