Results 1 to 8 of 8

Thread: [QT3] QComboBox: Disable adding items on Enter-keypress

  1. #1
    Join Date
    Jan 2006
    Location
    Netherlands
    Posts
    56
    Thanks
    10
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default [QT3] QComboBox: Disable adding items on Enter-keypress (solved)

    Hello

    I have a question.

    Is it possible to disable the function of a editable QComboBox to add items on a Enter-keypress ?

    see the screenshot, I don't want item1 to be added to the list when Enter is pressed.


    Thx in advance
    Last edited by BrainB0ne; 13th January 2006 at 14:07.
    ..:: Still Standing Strong ::..

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: [QT3] QComboBox: Disable adding items on Enter-keypress

    Install an event filter on it and filter out the return and enter keys.

  3. #3
    Join Date
    Jan 2006
    Location
    Netherlands
    Posts
    56
    Thanks
    10
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: [QT3] QComboBox: Disable adding items on Enter-keypress (solved)

    Quote Originally Posted by wysota
    Install an event filter on it and filter out the return and enter keys.
    So it means I have to subclass QComboBox (e.g MyComboBox) and override keyPressEvent by adding it to MyComboBox?


    edit: thx wysota, you solved my problem
    Last edited by BrainB0ne; 13th January 2006 at 14:00.
    ..:: Still Standing Strong ::..

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: [QT3] QComboBox: Disable adding items on Enter-keypress

    No, you have to apply an "eventFilter" (installEventFilter() and eventFilter()).

  5. #5
    Join Date
    Jan 2006
    Location
    Netherlands
    Posts
    56
    Thanks
    10
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: [QT3] QComboBox: Disable adding items on Enter-keypress

    Quote Originally Posted by wysota
    No, you have to apply an "eventFilter" (installEventFilter() and eventFilter()).
    Thx! I will try it out on Monday at my work, didn't realize that you meant this..
    The subclassing method worked also, but your solution looks better
    ..:: Still Standing Strong ::..

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: [QT3] QComboBox: Disable adding items on Enter-keypress

    Quote Originally Posted by BrainB0ne
    Thx! I will try it out on Monday at my work, didn't realize that you meant this..
    The subclassing method worked also, but your solution looks better
    It's not "better". It's "quicker" and "simpler"

  7. #7
    Join Date
    Jan 2006
    Location
    Moscow, Russia
    Posts
    20
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: [QT3] QComboBox: Disable adding items on Enter-keypress

    May be you should try method setInsertionPolicy( QComboBox::NoInsertion).

  8. #8
    Join Date
    Jan 2006
    Location
    Netherlands
    Posts
    56
    Thanks
    10
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: [QT3] QComboBox: Disable adding items on Enter-keypress

    Quote Originally Posted by vitaly
    May be you should try method setInsertionPolicy( QComboBox::NoInsertion).
    Thank you also for your solution.. will try it out after this weekend

    edit: Vitaly, I used your solution, seems to work great for my application
    Last edited by BrainB0ne; 16th January 2006 at 09:57.
    ..:: Still Standing Strong ::..

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.