我是PyQt的新手。我一直在寻找如何找到我的PyQt应用程序的窗口,它目前是打开的,并把它放在前面。到目前为止,我只找到一个使用pywin32的例子(因此是windows特有的)。我想问一下,是否有一种独立于平台的方式来实现这一目标。任何帮助都将不胜感激。在
这是我的密码。activateWindow()函数应该将它放在最前面。在
class TestApp(QtGui.QApplication):
def __init__(self, argv, key):
QtGui.QApplication.__init__(self, argv)
self._activationWindow=None
self._memory = QtCore.QSharedMemory()
self._memory.setKey(key)
if self._memory.attach():
self._running = True
else:
self._running = False
if not self._memory.create(1):
raise RuntimeError(
self._memory.errorString().toLocal8Bit().data())
def isRunning(self):
return self._running
def activationWindow(self):
return self._activationWindow
def setActivationWindow(self, activationWindow):
self._activationWindow = activationWindow
def activateWindow(self):
if not self._activationWindow:
return
self._activationWindow.setWindowState( self._activationWindow.windowState() & ~QtCore.Qt.WindowMinimized | QtCore.Qt.WindowActive)
self._activationWindow.raise_()
self._activationWindow.show()
self._activationWindow.activateWindow()
一个完整的、不依赖于平台的解决方案可能是遥不可及的。Qt支持的每个平台都有不同的行为方式,
activateWindow
似乎有点缺陷。在首先,Qt文档对
activateWindow
的描述如下:以及:
要获得更多关于困难的确凿证据,请查看Qt论坛上的以下帖子:
相关问题 更多 >
编程相关推荐