[Interest] Receive key presses when hovering over a specific widget
tony at rightsoft.com.au
Thu Jul 11 17:57:45 CEST 2019
AFAIK, the easiest way to trap keyPress/keyRelease irrespective of which
widget has the focus is to install an event filter on the QApplication
instance. Use the mouseEnter/Leave events of the thumbnails to
set/clear a currentThumbnail, and then in eventFilter only act on the
'm' keyPress if the currentThumbnail has been set, and return false from
the filter, otherwise return true so that the 'm' will go to the edit
box or whatever.
On 11/07/2019 9:53 pm, Murphy, Sean wrote:
> I'm trying to figure out the best way to receive key presses when the user hovers over a specific widget, and deliver that keypress information to the parent widget.
> Say I've got three types of widgets:
> 1. thumbnailWidget - displays a low resolution version of a full resolution image, essentially based on QLabel
> 2. imageLibraryWidget - displays 1-N image thumbnail widgets. This widget is based on QWidget. Also owns all the full resolution images used to create the thumbnails
> 3. magnifierWidget - popup widget that displays a full resolution subset of the thumbnail. Think of it as just a magnifying glass that you can put over a portion of the thumbnail
> Application hierarchy is as follows:
> - MainWindow
> - multiple "other" widgets, some of which can receive keyboard focus (QLineEdits, QTextEdits, etc.)
> - one or more imageLibraryWidgets
> - multiple "other" widgets, some of which can receive keyboard focus
> - one or more imageThumbnailWidgets
> - one magnifierWidget
> So the way I want this to work is that when the user hovers over a thumbnail widget AND presses a specific key, the imageLibraryWidget that is the parent of that thumbnail is notified that the correct keypress has been received, and knows which thumbnail (and which pixel of that thumbnail) the cursor is over. It then will popup the magnifierWidget with the appropriate full resolution pixels. When the user releases the key, or moves the mouse so they are no longer over a thumbnail, the magnifier is hidden.
> I've got the mouse position portion taken care of, but I'm struggling to get the key press thing correct, especially given that other widgets (either child widgets of the imageLibraryWidget or children of MainWindow) might have the keyboard focus at the time the user moves the mouse over a thumbnail and presses the bound key. I still want the magnifier idea to work, ideally without changing the keyboard focus from the currently focused widget.
> So the following should work:
> 1. User starts to type something in a line edit
> 2. Before finishing what they're typing they decide they need to double check something in the related image
> 3. User move cursor over image, and presses the key bound to the magnifier functionality. Let's say the key is 'm'
> 4. While over the image, and they are holding down the 'm' key, the keypress should be consumed and not get entered into the line widget
> That's the ideal case, I can live with it if the user would lose keyboard focus in the line edit and has to click back in it after the above sequence if I have to.
> Thoughts about how to go about this? I think I might need some combination of event filters and QHoverEvents, but not sure of the right combo at the moment.
> This message has been scanned for malware by Forcepoint. www.forcepoint.com
> Interest mailing list
> Interest at qt-project.org
More information about the Interest