【发布时间】:2021-12-27 17:08:23
【问题描述】:
我创建了一个没有任何标题栏且透明的 pyqt 窗口。还为我的窗口添加了蓝色边框,但是在运行应用程序时,我看不到窗口的任何蓝色边框。
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import Qt
import sys
class Window(QMainWindow):
def __init__(self):
super().__init__()
# this will hide the title bar
self.setWindowFlag(Qt.FramelessWindowHint)
self.setStyleSheet("border : 3px solid blue;")
self.setWindowOpacity(0.01)
# setting the geometry of window
self.setGeometry(100, 100, 400, 300)
self.showFullScreen()
# create pyqt5 app
App = QApplication(sys.argv)
# create the instance of our Window
window = Window()
window.show()
# start the app
sys.exit(App.exec())
如何显示窗口的边框?
【问题讨论】:
-
您看不到边框,因为您使窗口几乎完全透明。此外,如果窗口显示为全屏,
FramelessWindowHint是不必要的,因为全屏窗口已经隐藏了框架和标题栏。出于同样的原因,设置几何图形也毫无意义。 -
@musicamante 这个问题有悬赏,不用paintEvent你能回答吗
-
@FarhanAhmed 使用绘画事件有什么问题?
-
如赏金描述中提到的
I want paintEvent to be called when the user drags the mouse to create rectangle on screen. So I don't want paintEvent to draw blue border everytime the self.update is called. I know I can use if to draw the border only once. But I do not want to do that -
@HimanshuPoddar 1. 请使用@username; 2.你不能“只画一次边框”,因为绘图不是这样工作的:
paintEvent在系统需要时被调用,甚至在一秒钟内调用几十次,你可以做nothing 关于它; 3. 如果您希望仅在某些情况下显示边框,请创建一个内部变量,在您想要绘制边框时设置它,然后只需在paintEvent()中检查该变量; 4. 这个问题是关于不显示边框的,而当前接受的答案解决了,您应该为您的 newnew 问题/i> 要求。
标签: python pyqt pyqt5 desktop-application qapplication