<html>
<head>
<meta name="generator" content="Windows Mail 17.5.9600.20498">
<style data-externalstyle="true"><!--
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph {
margin-top:0in;
margin-right:0in;
margin-bottom:0in;
margin-left:.5in;
margin-bottom:.0001pt;
}
p.MsoNormal, li.MsoNormal, div.MsoNormal {
margin:0in;
margin-bottom:.0001pt;
}
p.MsoListParagraphCxSpFirst, li.MsoListParagraphCxSpFirst, div.MsoListParagraphCxSpFirst,
p.MsoListParagraphCxSpMiddle, li.MsoListParagraphCxSpMiddle, div.MsoListParagraphCxSpMiddle,
p.MsoListParagraphCxSpLast, li.MsoListParagraphCxSpLast, div.MsoListParagraphCxSpLast {
margin-top:0in;
margin-right:0in;
margin-bottom:0in;
margin-left:.5in;
margin-bottom:.0001pt;
line-height:115%;
}
--></style></head>
<body dir="ltr">
<div data-externalstyle="false" dir="ltr" style="font-family: 'Calibri', 'Segoe UI', 'Meiryo', 'Microsoft YaHei UI', 'Microsoft JhengHei UI', 'Malgun Gothic', 'sans-serif';font-size:12pt;"><div>Dear community,</div><div><br></div><div>I am trying to create a Windows application containing a QMainWindow that also open up several QFrame window containing some buttons in it. It sort of like a free floating tool window. But the problem is, when I click button on a floating QFrame, the main window lost its focus. Giving unpleasant experience to the user.</div><div><br></div><div>I have found an answer actually, that should’ve solve this problem: using win32con.WS_EX_NOACTIVATE. But somehow, I still unable to properly applied this extended style. This is the SO page containing this solution : <a href="http://stackoverflow.com/questions/18662031/avoid-application-activation-and-focus-in-when-clicking-buttons-on-it-windows/18774481?noredirect=1#comment38088304_18774481" target="_parent">http://stackoverflow.com/questions/18662031/avoid-application-activation-and-focus-in-when-clicking-buttons-on-it-windows/18774481?noredirect=1#comment38088304_18774481</a></div><div><br></div><div>This is my Python code using PyWin32 libraries to try to use that extended style:</div><div><br></div><div> def no_focus(self):<br> """<br> TODO Suppose to create a non stealing focus window.<br> Not working yet<br> """<br> import ctypes<br> import win32con<br> import win32gui</div><div><br></div><div> dc = win32gui.GetWindowDC(self.winId())<br> user32 = ctypes.windll.user32<br> existing_style = user32.GetWindowLongW(dc, win32con.GWL_EXSTYLE)<br> user32.SetWindowLongW(dc, win32con.GWL_EXSTYLE, existing_style | win32con.WS_EX_NOACTIVATE | win32con.WS_EX_TOOLWINDOW)</div><div><br></div><div>Based on that SO page, I have also try to override showEvent(), but to no result:</div><div><br></div><div> def showEvent(self, *args, **kwargs):<br> self.no_focus()<br> super(FSFloatingFrame, self).showEvent(*args)</div><div><br></div><div><br></div><div>My current partial solution, is to trap eventFilter for QEvent.WindowActivate in my tool window base class, and activateWindow() for the mainwindow. But it also stop all the buttons from functioning.</div><div><br></div><div>def eventFilter(self, object, QEvent):<br> if QEvent.type() == QEvent.WindowActivate:<br> #this half solve the problem: window won't steal focus: but it also make no action to the buttons<br> #self.mainwindow.activateWindow()<br> pass<br> return super(FSFloatingFrame, self).eventFilter(object, QEvent)</div><div><br></div><div>Any suggestion on this particular case?</div><div>I am quite wonder whether tool window that behave like it’s a tool window (non stealing focus) have already been provided by Qt…</div><div><br></div><div>Thanks in advance!</div><ul style="padding-top: 0px; padding-bottom: 0px; margin-top: 0px; margin-bottom: 0px; list-style-type: disc;"><li style='color: rgb(0, 0, 0); font-family: "Color Emoji", "Calibri", "Segoe UI", "Meiryo", "Microsoft YaHei UI", "Microsoft JhengHei UI", "Malgun Gothic", "sans-serif"; font-size: 16px;'><div>Eko</div></li></ul><div><br></div><div><br></div></div>
</body>
</html>