Important: Please read the Qt Code of Conduct -

Draw the QPushButton on the widget embedded with libvlc - MacOS

  • I have a program that plays video with LibVLC, and I want to put some circular buttons on top of the VLC Widget for a barrage effect.

    This is my test code.

    # -*- coding: utf-8 -*-
    import sys
    import os
    import vlc
    from PySide2 import QtCore, QtGui, QtWidgets
    class RoundButton(QtWidgets.QPushButton):
        def __init__(self, radius, *args, **kwargs):
            super(RoundButton, self).__init__(*args, **kwargs)
            self._radius = radius
        def resizeEvent(self, event):
            r = self.rect()
            rb = QtCore.QRect(0, 0, 2*self._radius, 2*self._radius)
            reg = QtGui.QRegion(rb, QtGui.QRegion.Ellipse)
            reg += QtGui.QRegion(rb, QtGui.QRegion.Ellipse)
            reg += QtGui.QRegion(rb, QtGui.QRegion.Ellipse)
            reg += QtGui.QRegion(rb, QtGui.QRegion.Ellipse)
            reg += QtGui.QRegion(self._radius, 0, r.width() - 2*self._radius, r.height())
            reg += QtGui.QRegion(0, self._radius, r.width(), r.height() - 2*self._radius)
            super(RoundButton, self).resizeEvent(event)
    class demo_widget(QtWidgets.QWidget):
        def __init__(self):
            super(demo_widget, self).__init__()
        def __ui__(self):
            self.resize(600, 400)
            t_lay_parent = QtWidgets.QHBoxLayout(self)
            t_lay_parent.setContentsMargins(0, 0, 0, 0)
            self.frame_media = QtWidgets.QFrame()
            self.pushButton_test = RoundButton(10, "Test", self)
            self.pushButton_test.setFixedSize(70, 30)
            self.pushButton_test.setAttribute(QtCore.Qt.WA_TranslucentBackground, True)
                                                      border:1px solid #36404A;
            self.pushButton_test.move(265, 185)
            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
            elif sys.platform == "win32": # for Windows
            elif sys.platform == "darwin": # for MacOS
        def slt_play(self):
            media = self.instance.media_new("1111.m4v")
    if __name__ == '__main__':
        app = QtWidgets.QApplication(sys.argv)
        demo = demo_widget()

    It works as expected on Windows and Linux, but on MacOS the button is under video.

    This is the ideal working screenshot.
    0_1537931426008_屏幕快照 2018-09-25 下午4.24.02.png

    But actually the button is under video, and it's covered by video.
    0_1537931489218_屏幕快照 2018-09-25 下午4.16.19.png

    I tried to add the following Settings to the button, and it successfully worked as expected, but it ran outside the window.

    self.pushButton_test.setWindowFlags(QtCore.Qt.SplashScreen | QtCore.Qt.FramelessWindowHint)

    Is there a better way to float the button above video?

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Did you already check the VLC-Qt project ? I don't know whether there are Python bindings yet but worth taking a look.

  • @SGaist I'm sorry I can't test vlc-qt because I don't know much about c++.
    I discovered through Google that a project using vlc-qt had the same problems as mine.

  • Lifetime Qt Champion

    From what's on the report, QtQuick would be a better choice for the UI in that case.

Log in to reply