Results 1 to 3 of 3

Thread: How to capture a right click in QComboBox

  1. #1
    Join Date
    Jan 2020
    Posts
    37
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default How to capture a right click in QComboBox

    What is the correct way to capture a right click in a QComboBox with a QCompleter? I want the completer to work as normal, but I also want to allow the user to right click in the combo lineedit and see the whole list of textstrings in the model. I have tried sub-classing both QComboBox and QCoompleter and reimplementing "mousePressEvent", but the method isn't called in either case. Do I need an event filter here? If so, should it be in the sub-classed combo or in the completer? The idea is to capture the right click and then incapacitate the completer. Or perhaps there is a more elegant way to achieve this?

  2. #2
    Join Date
    Jan 2020
    Posts
    37
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: How to capture a right click in QComboBox

    I just found out that I can capture the muse click when I (left)click on the QComboBox's right hand side down arrow, and this is even better than a right click. So problem solved. However, I couldn't find anything about this in the docs. Perhaps I looked in the wrong place?

    Out of courosity: the reason it doesn't work when I click in the combo's lineedit it probably because I then "somehow" need to specify that in the mousePressEvent function?

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,719
    Thanks
    259
    Thanked 760 Times in 750 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: How to capture a right click in QComboBox

    Out of courosity: the reason it doesn't work when I click in the combo's lineedit it probably because I then "somehow" need to specify that in the mousePressEvent function?
    This doesn't make any sense. You don't call the mousePressEvent() handler, Qt's event loop does, in response to something generated deep in the internals of your mouse's device driver. So how can you "somehow" specify anything? The event you get describes something that has already happened, it doesn't provide a way for you to specify what happens sometime in the future or for some widget other than the one clicked..

    What is more likely is that the combination of editability settings, completers, and other things you have set on your combo box have resulted in right-click events being processed and eaten so they never reach the level of your code. You can try setting an event filter on both the combo box and the line edit inside it to see if you actually do get those events (event filters are called before the widget itself gets a whack at the event).
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Proper use of an InputDialog box - capture CANCEL click
    By emp1953 in forum Qt Programming
    Replies: 2
    Last Post: 10th November 2017, 18:42
  2. Replies: 0
    Last Post: 24th May 2016, 13:53
  3. Replies: 1
    Last Post: 3rd April 2016, 01:10
  4. How to add items while click on QCombobox
    By RameshNani in forum Qt Programming
    Replies: 2
    Last Post: 4th February 2014, 08:07
  5. incorrected QComboBox capture screen.
    By minsoub in forum Newbie
    Replies: 3
    Last Post: 25th February 2010, 02:13

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.