我有一个用LibVLC播放视频的程序,我想在VLC小部件的顶部放置一些圆形按钮,以获得阻拦效果。你知道吗
这是我的测试代码。你知道吗
# -*- coding: utf-8 -*-
import sys
import os
import vlc
from PySide2.QtWidgets import *
from PySide2.QtGui import *
from PySide2.QtCore import *
class demo_widget(QWidget):
def __init__(self):
super(demo_widget, self).__init__()
self.__ui__()
def __ui__(self):
self.resize(600, 400)
t_lay_parent = QHBoxLayout()
t_lay_parent.setContentsMargins(0, 0, 0, 0)
self.frame_media = QFrame(self)
t_lay_parent.addWidget(self.frame_media)
self.setLayout(t_lay_parent)
self.pushButton_test = QPushButton("Test", self)
self.pushButton_test.setFixedSize(70, 30)
self.pushButton_test.setStyleSheet("QPushButton{background-color:#36404A;border:1px solid #36404A;border-radius:10px;color:#98A6AD;}")
self.pushButton_test.move(265, 185)
self.pushButton_test.clicked.connect(self.slt_play)
self.instance = vlc.Instance("--network-caching=1000 --http-continuous")
self.player = self.instance.media_player_new()
if sys.platform.startswith('linux'): # for Linux using the X Server
self.player.set_xwindow(self.frame_media.winId())
elif sys.platform == "win32": # for Windows
self.player.set_hwnd(self.frame_media.winId())
elif sys.platform == "darwin": # for MacOS
self.player.set_nsobject(self.frame_media.winId())
def slt_play(self):
media = self.instance.media_new("1111.m4v")
self.player.set_media(media)
self.player.play()
app = QApplication(sys.argv)
demo = demo_widget()
demo.show()
sys.exit(app.exec_())
我试图添加以下设置到按钮,它成功地按预期工作,但它在窗口外运行。你知道吗
self.pushButton_test.setWindowFlags(Qt.SplashScreen | Qt.FramelessWindowHint)
self.pushButton_test.setAttribute(Qt.WA_TranslucentBackground, True)
有没有更好的方法来画一个透明的圆角按钮?你知道吗
一种可能的解决方案是将
QRegion
与setMask()
一起使用:相关问题 更多 >
编程相关推荐