Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyQt Irregularly Shaped Windows (e.g. A circular without a border/decorations)

Tags:

python

pyqt

How do I create an irregularly shaped window in PyQt?

I found this C++ solution, however I am unsure of how to do that in Python.

like image 657
Nathan Avatar asked Jan 15 '13 21:01

Nathan


1 Answers

Here you go:

from PyQt4 import QtGui, QtWebKit
from PyQt4.QtCore import Qt, QSize

class RoundWindow(QtWebKit.QWebView):
    def __init__(self):
        super(RoundWindow, self).__init__()
        self.initUI()

    def initUI(self):
        self.setWindowFlags(Qt.FramelessWindowHint)
        self.setAttribute(Qt.WA_TranslucentBackground)

    def sizeHint(self):
        return QSize(300,300)

    def paintEvent(self, event):
        qp = QtGui.QPainter()
        qp.begin(self)
        qp.setRenderHint(QtGui.QPainter.Antialiasing);
        qp.setPen(Qt.NoPen);
        qp.setBrush(QtGui.QColor(255, 0, 0, 127));
        qp.drawEllipse(0, 0, 300, 300);
        qp.end()

a = QtGui.QApplication([])
rw = RoundWindow()
rw.show()
a.exec_()

Screenshot

I've never written C++ in my life, but reading that code example was not that hard. You'll find that most Qt documentation online is in C++, so it's useful to at least be able to read.

like image 104
Fredrick Brennan Avatar answered Sep 18 '22 16:09

Fredrick Brennan