Results 1 to 7 of 7

Thread: QLineEdit ignore key Qt:Key_Asterisk

  1. #1
    Join Date
    Dec 2009
    Posts
    65
    Thanks
    10
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default QLineEdit ignore key Qt:Key_Asterisk

    i have two separate widgets in one layout
    first widget accepts keyboard shortcuts like this
    Qt Code:
    1. QAction *fnQuantity = new QAction(this);
    2. fnQuantity->setShortcut(Qt::Key_Asterisk);
    3. connect(fnQuantity, SIGNAL(triggered()), this, SLOT(on_editQuantity_clicked()));
    4. this->addAction(fnQuantity);
    To copy to clipboard, switch view to plain text mode 
    the second widget has some QLineEdit fields and radio buttons on form, some of them are disabled
    If one of qLineEdit fields has focus, when i press asterisk on numpad it just types * character in lineedit
    if i click on one of disabled fields, or radio butons, and then press * on keyboard the action in first form is executed
    I tried with overriding keypressevent on qlineedit, and installing event filter in second form but all i get is that * sign is not typed into QLineEdit, and fnQuantity action is not executed
    How can i ignore asterisk sign from line edit... and let other widgets process it...?

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QLineEdit ignore key Qt:Key_Asterisk

    In the slot on_editQuantity_clicked() check if the widget has focus. If they do not do anything.

  3. #3
    Join Date
    Dec 2009
    Posts
    65
    Thanks
    10
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: QLineEdit ignore key Qt:Key_Asterisk

    i want on_editQuantity_clicked() to get executed even when the focus is on qlineedit on second form, but it is not executed, because qlineedit takes that key and appends * in its text property and ends there...

  4. #4
    Join Date
    Dec 2009
    Posts
    65
    Thanks
    10
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: QLineEdit ignore key Qt:Key_Asterisk

    I am still trying to figure this out. The same issue is how to ignore some keyboard events in QLineEdit
    On first widget i have two buttons with shortcuts [ctrl+a] and [ctrl+d] and tableview. On second sibling widget there is qlineedit that usualy holds the focus and some radio buttons
    if i press ctrl+d the button [ctrl+d] gets clicked
    if i press ctrl+a the text in qlineedit gets selected (select all shortcut)
    Qt Code:
    1. ---------------|---------------------
    2. | [ctrl+a] | --------------- |
    3. | [ctrl+d] | | qlineedit | |
    4. | | --------------- |
    5. | table | radio buttons |
    6. ---------------|--------------------
    To copy to clipboard, switch view to plain text mode 
    i tried subclassing qlineedit and ignoring some key events, but all i get is that that key event is ignored, and not passed like ctrl+d is.
    when i see that ctrl+d is passed that makes me think that it is possible to do the same with other keys, but i cant make it work
    i also wanted to use up and down arrows while in qlineedit to navigate table on first widget.
    Can i achieve this by just editing second widget event/eventfilter? How? What am i missing?

  5. #5
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: QLineEdit ignore key Qt:Key_Asterisk

    I think you have installed the key action on the buttons, install the same action on the QLineEdit too.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  6. #6
    Join Date
    Dec 2009
    Posts
    65
    Thanks
    10
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: QLineEdit ignore key Qt:Key_Asterisk

    I don't quite understand what you mean, (btw i don't even understand your quote/signature message )
    In my first attempt (first message) i created 2 qactions in first widget. Two widgets are complete separate files, loaded dynamically into one layout and have no knowledge of each other except that when second completes its job it sends signal to first, the second holds the focus.
    In first widget created two actions that have shortcuts F2 and F3, when qlineedit has focus and i press F2 or F3, the actions are executed
    Then i tried to change action shortcuts to asterisk (*) and slash (/) (Key_Asterisk and Key_Slash). If i have QLineEdit in focus actions are not executed but text is appended to lineedit, like it should.
    But i want to create special case and for this lineedit and ignore those events just like F2 and F3 keys are ignored, and not just ignored but appropriate actions get executed.
    I subclassed QLIneedit, changed its keyEvent, event.. i subclassed second widget and reimplemented eventFilter but all i get is that those keypresses are ignored, no text is appended to lineedit, but actions are not executed.
    How can i make Asterisk key invisible for QLineEdit like F2 key is and
    I also wanted to use shortcuts ctrl+a, up arrow, down arrow and ctrl+d. Those shortcuts are set on first widgets for buttons via qtdesigner (property manager), and only ctrl+d works while in qlineedit focus
    if the focus is on radiobuttons on second widget all those shortcuts from first widget work, so the thing that those two widgets are siblings and that focus is on another widget is not the problem, right!?
    What i have to do to my QLineEdit so it behaves the same way as radiobutton when in focus (concerning those shortcuts)
    I think i have to subclass it (like i did) unregister something... but what

  7. #7
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: QLineEdit ignore key Qt:Key_Asterisk

    Hope this helps
    Qt Code:
    1. class LineEdit : public QLineEdit
    2. {
    3. Q_OBJECT
    4. public:
    5. explicit LineEdit(QWidget * parent = 0) : QLineEdit(parent) { }
    6.  
    7. signals:
    8. void shortcutDetected();
    9.  
    10. protected:
    11. void keyPressEvent(QKeyEvent * event)
    12. {
    13. if(event->key() == Qt::Key_Asterisk)
    14. {
    15. event->accept();
    16. return;
    17. }
    18.  
    19. return QLineEdit::keyPressEvent(event);
    20. }
    21.  
    22. void keyReleaseEvent(QKeyEvent * event)
    23. {
    24. if(event->key() == Qt::Key_Asterisk)
    25. {
    26. event->accept();
    27. emit shortcutDetected();
    28. return;
    29. }
    30. }
    31. };
    To copy to clipboard, switch view to plain text mode 
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

Similar Threads

  1. Replies: 2
    Last Post: 9th July 2016, 10:59
  2. Replies: 0
    Last Post: 18th June 2013, 10:54
  3. Replies: 1
    Last Post: 12th October 2010, 22:20
  4. Some Signal Ignore
    By nicolas1 in forum Qt Programming
    Replies: 2
    Last Post: 31st December 2008, 02:07

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.