指定坐标处的 PyQt 无框窗口 [英] PyQt frameless window at specified coordinates

查看:26
本文介绍了指定坐标处的 PyQt 无框窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

经过多次谷歌搜索后,我知道我需要使用 self.setWindowFlags(QtCore.Qt.FramelessWindowHint)

After much googling I'm aware that I need to use self.setWindowFlags(QtCore.Qt.FramelessWindowHint)

生成一个无框窗口,并通过坐标 (0,0) 的一些变化将其放置在屏幕的左上角.

to generate a frameless window, and some variation of the co-ordinates (0,0) to place it in the upper left corner of the screen.

我遇到的问题是,在我尝试使用此代码的任何地方,它都会生成错误,即使在我现有的稀疏代码中也是如此:

The problem I'm having is that everywhere that I've tried using this code, it generates errors, even in my sparse existing code:

from PyQt4 import QtCore, QtGui
from ui.mainwindow import MainWindow

if __name__ == "__main__":
    import sys
    app = QtGui.QApplication(sys.argv)
    ui = MainWindow()
    ui.show()
    sys.exit(app.exec_())

经过多次谷歌搜索后,我无法制定对其他人有用的解决方案.让我的窗口在屏幕左上角无边框显示的魔术语法是什么?

After much googling I'm unable to make solutions that work for others work for me. What is the magic syntax to get my window displayed without borders in the upper left corner of the screen?

推荐答案

原来我有很多关于 Python 和层次继承的知识/什么属于 what-ness,我正在寻找的代码是:

It turns out I have a lot to learn about Python and hierarchical inheritance/ what belongs to what-ness, the code I was looking for is:

from PyQt4 import QtCore, QtGui
from ui.mainwindow import MainWindow

if __name__ == "__main__":
    import sys
    app = QtGui.QApplication(sys.argv)
    ui = MainWindow()
    ui.setWindowFlags(QtCore.Qt.FramelessWindowHint)
    ui.move(0, 0)
    ui.show()
    sys.exit(app.exec_())

尤里卡时刻意识到 MainWindow 伪装成变量 ui 下的速记.为了像我这样的菜鸟的利益.

The eureka moment was realising that MainWindow is masquerading in shorthand under the variable ui. For the benefit of others as nooby as me.

这篇关于指定坐标处的 PyQt 无框窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆