<div dir="ltr"><div>Sean:</div><div><br></div><div>Not sure if this fits your use case 100%, but might give you some ideas. I did something similar for magnifying images in QLabels, but I don't have your additional focus issue.<br><br>On the thing being magnified (QLabel-derived class holding the image):<br><br>- holds a pointer to the magnifier and sets itself as the target of the magnifier<br>- in the keyPressEvent I look for Qt::Key_M and tell the magnifier it's active (which shows it)<br>- in the keyReleaseEvent event I tell the magnifier it's not active (which hides it)<br></div><div>- (for your case you might need to use enter/leave events to intercept the keyboard? or maybe QWidget::underMouse()?)</div><div><br></div><div>In my magnifier class (QWidget-derived):<br><br>- it draws itself using info from the target widget<br>- installs an event filter on the target<br> - handles mouse move to update the location/contents<br> - handles enter and leave events to show/hide itself by checking the mouse location against the target widget using QCursor::pos() (note that QWidget::underMouse() will not work because the mouse may be over the magnifier)<br>- also need to set some flags & attributes:<br> setWindowFlags( Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint );<br><br> setAttribute( Qt::WA_ShowWithoutActivating );<br> setAttribute( Qt::WA_TransparentForMouseEvents );<br></div><div><br></div><div><br>I found it pretty tricky to get working (and I still have a couple of things I'm not happy with) but it's very close (shippable!).<br><br>Good luck!</div><div><br></div><div><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div>---<br>Andy Maloney // <a href="https://asmaloney.com" target="_blank">https://asmaloney.com</a><br><div>twitter ~ <span dir="ltr"><a href="https://twitter.com/asmaloney" target="_blank">@<span>asmaloney</span></a></span></div></div></div></div></div></div></div></div></div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jul 11, 2019 at 7:54 AM Murphy, Sean <<a href="mailto:smurphy@walbro.com">smurphy@walbro.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">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.<br>
<br>
Say I've got three types of widgets:<br>
1. thumbnailWidget - displays a low resolution version of a full resolution image, essentially based on QLabel<br>
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<br>
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<br>
<br>
Application hierarchy is as follows:<br>
- MainWindow<br>
- multiple "other" widgets, some of which can receive keyboard focus (QLineEdits, QTextEdits, etc.)<br>
- one or more imageLibraryWidgets<br>
- multiple "other" widgets, some of which can receive keyboard focus<br>
- one or more imageThumbnailWidgets<br>
- one magnifierWidget<br>
<br>
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.<br>
<br>
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.<br>
<br>
So the following should work:<br>
1. User starts to type something in a line edit<br>
2. Before finishing what they're typing they decide they need to double check something in the related image<br>
3. User move cursor over image, and presses the key bound to the magnifier functionality. Let's say the key is 'm'<br>
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<br>
<br>
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.<br>
<br>
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.<br>
Sean<br>
<br>
<br>
<br>
<br>
<br>
This message has been scanned for malware by Forcepoint. <a href="http://www.forcepoint.com" rel="noreferrer" target="_blank">www.forcepoint.com</a><br>
_______________________________________________<br>
Interest mailing list<br>
<a href="mailto:Interest@qt-project.org" target="_blank">Interest@qt-project.org</a><br>
<a href="https://lists.qt-project.org/listinfo/interest" rel="noreferrer" target="_blank">https://lists.qt-project.org/listinfo/interest</a><br>
</blockquote></div>