在Qt中,我可以使用窗口标志“Qt :: WindowStaysOnTopHint”来确保我的窗口始终在其他所有窗口上。
但是,当我运行全屏游戏时,这不起作用。看起来“全屏”取代了窗口控制器。
有人说我应该用directX做一些工作,或者覆盖游戏的DLL。
如果有一种简单的方法可以完成这项工作?请告诉我。
在此处显示我的代码:
from PyQt4.QtGui import *
from PyQt4.QtCore import *
import sys
from threading import Thread
import pyhk
class Aim(QDialog):
signal_visible = pyqtSignal()
signal_color = pyqtSignal()
signal_fresh = pyqtSignal()
Range = 8
Color = 'red'
Color_dict = {
'red': QColor(255,0,0,255),
'green': QColor(0,255,0,255),
'blue': QColor(0,0,255,255)
}
Color_list = ['red','green','blue']
def __init__(self):
super(Aim,self).__init__()
self.initUI()
self.initSignal()
def initUI(self):
self.resize(100,100)
sx,sy = self.getCenter()
self.move(sx/2-50,sy/2-50)
self.setWindowFlags(Qt.FramelessWindowHint|Qt.WindowStaysOnTopHint|Qt.Tool)
self.setAttribute(Qt.WA_TranslucentBackground)
def initSignal(self):
self.signal_visible.connect(self.change_visible)
self.signal_color.connect(self.change_color)
self.signal_fresh.connect(self.fresh)
def paintEvent(self, e):
painter = QPainter()
painter.begin(self)
painter.setRenderHint(QPainter.Antialiasing,True)
# self.drawAim_Point(painter)
self.drawAim_Circle(painter)
# self.drawAim_Lines(painter)
# self.drawAim_GradPoint(painter)
painter.end()
def drawAim_Circle(self,painter):
color = self.Color_dict[self.Color]
painter.setPen(QPen(color,0,Qt.SolidLine))
# painter.setBrush(QBrush(color,Qt.SolidPattern))
size = self.size()
x = 50
y = 50
painter.drawPoint(x, y)
painter.drawPoint(x-1, y)
painter.drawPoint(x, y-1)
painter.drawPoint(x-1, y-1)
painter.setBrush(QBrush())
r = self.Range * 3
painter.drawEllipse(x-r/2, y-r/2, r, r)
def getCenter(self):
desktopWidget = QApplication.desktop()
deskRect = desktopWidget.availableGeometry()
screenRect = desktopWidget.screenGeometry()
return (screenRect.width(),screenRect.height())
def change_visible(self):
flag = self.isVisible()
if flag == True:
self.setVisible(False)
else:
self.setVisible(True)
def change_color(self):
index = self.Color_list.index(self.Color)+1
if index == len(self.Color_list):
index = 0
self.Color = self.Color_list[index]
self.repaint()
def fresh(self):
self.hide()
self.setWindowFlags(Qt.FramelessWindowHint|Qt.WindowStaysOnTopHint|Qt.Tool)
self.repaint()
self.show()
def hotKeySet():
global handle
handle=pyhk.pyhk()
HOTKEY= {
1:['Alt','F1'],
2:['Alt','F12'],
3:['Alt','F11'],
4:['Alt','F2']
}
ACTION= {
1:hk_exit,
2:hk_show,
3:hk_color,
4:hk_fresh
}
for i in range(1, len(HOTKEY)+1):
handle.addHotkey(HOTKEY[i],ACTION[i])
handle.start()
def hk_show():
aim.signal_visible.emit()
def hk_exit():
handle.end()
sys.exit()
def hk_color():
aim.signal_color.emit()
def hk_fresh():
aim.signal_fresh.emit()
def main():
global aim,hkt
hkt = Thread(target=hotKeySet)
hkt.start()
app = QApplication(sys.argv)
aim = Aim()
aim.setVisible(True)
sys.exit(app.exec_())
if __name__ == '__main__':
main()