Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Disable the default behavior of the QlistWidget of chaging focus when keyboard key press matches first letter of text in a item
Forum Updated to NodeBB v4.3 + New Features

Disable the default behavior of the QlistWidget of chaging focus when keyboard key press matches first letter of text in a item

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 1.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    alkimia
    wrote on last edited by
    #1

    Hi Everyone,

    So I'm just new at QT and I have Qlstwidget and im using de 'D' key to disable(changes icon) of items from the list, but every time I press D and there are items that start with the letter D the focus/selection/current item changes and it's just anoying , is there a way to disable this default behavior, so when I press a letter doesn't go to the items starting with that letter?

    thanks in Advance,

    1 Reply Last reply
    0
    • AndeolA Offline
      AndeolA Offline
      Andeol
      wrote on last edited by
      #2

      Hi,

      If you inherit from QListWidget, you can override the keyPressEvent() function, and handle the press on D however you want.
      Something like:

      // Class declaration. Inherit from QlstWidget
      class MyWidget : public QlstWidget {
      protected: 
      void keyPressEvent(QKeyEvent *event) ;
      }
      
      // And implement the keyPressEvent method
      MyWidget::keyPressEvent(QKeyEvent *event) {
             if(event->key() == Qt::key_D) {
                       //disable item from the list
             }
             else {
                      // call the native function in any other case (or don't, if you never care about the QlstWidget receiving other key events)
                      Qlstwidget::keyPressEvent(event);
             }
      

      If you don't want to derive your own class from Qlstwidget, you can also use an eventfilter (http://doc.qt.io/qt-5/qobject.html#installEventFilter).

      Eventfilters allow you to "intercept" the event destined to another widget. You can then decide to call some methods depending on this event, and then relay the item to its original destination (if desired).

      Developer for R++ : https://rplusplus.com/

      1 Reply Last reply
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved