0

In Qt, I can use window flag “Qt::WindowStaysOnTopHint” to make sure my window always on other all windows.

But, when I am running a fullscreen game, that does not work. Looks like the “fullscreen”takes place of the window controller.

Someone says that I should do some work with directX, or overwrite the game`s DLLs.

If there is an easy way to done this work? Please tell me.

Show my code HERE:

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()
pingze
  • 973
  • 2
  • 9
  • 18
  • Short answer: There *is* no easy way. – Bo Persson Aug 21 '16 at 09:16
  • "my window always on other all windows", hint: what happens if 2 applications try to do this at the same time? – Richard Critten Aug 21 '16 at 09:40
  • When that happens, the later one will be on top. That's not the problem. The important question is how to make it on a fullscreen application.I know the Fraps [link](http://www.fraps.com/) can do that, and I want to find how it works. @Richard Critten – pingze Aug 21 '16 at 12:17
  • @pingze - they would fight; that's why there is no API for this. App (A) detects not on top - moves to top; App (B) detects not on top - moves to top .... rinse and repeat – Richard Critten Aug 21 '16 at 12:27
  • @Richard Critten - I have tried this. They did not repeat, at least in my code. I start a copy of my code, and the copy just moves to top. But when I use the function fresh()(In my code), the original one moves to top instead of the copy. – pingze Aug 21 '16 at 12:42
  • I think it may be useful to hook the graphics card‘s API, or DX and openGL API. – pingze Aug 21 '16 at 12:48
  • You might want to read this: https://blogs.msdn.microsoft.com/oldnewthing/20050607-00/?p=35413 – Richard Critten Aug 21 '16 at 12:53

0 Answers0