Issue
I want to make to make an application where just the drawn objects (ex. drawLine) is visible, not the background.
So, if a user opens up the application, he/she can draw shapes, and only see the shapes drawn.
I'm new to pyside, but I've found examples where only the widget is visible, but I don't think that applies to this problem.
a = QPoint(22, 22)
b = QPoint(444, 444)
def __init__(self, parent=None):
QWidget.__init__(self, parent)
self.setGeometry(300, 300, 350, 350)
self.setWindowTitle('Draw circles')
def paintEvent(self, event):
paint = QPainter()
paint.begin(self)
paint.drawLine(self.a, self.b)
paint.end()
The above program is just an example of a line drawn on an opaque background. Not sure how to go from this to a transparent background.
Solution
You must enable the flag Qt::WA_TranslucentBackground
:
from PySide import QtCore, QtGui
class Widget(QtGui.QWidget):
def __init__(self, parent=None):
super(Widget, self).__init__(parent)
self.setAttribute(QtCore.Qt.WA_TranslucentBackground, True)
def paintEvent(self, event):
a = QtCore.QPoint(22, 22)
b = QtCore.QPoint(444, 444)
painter = QtGui.QPainter(self)
pen = QtGui.QPen(QtGui.QColor("red"))
pen.setWidth(5)
painter.setPen(pen)
painter.drawLine(a, b)
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
w = Widget()
w.resize(640, 480)
w.show()
sys.exit(app.exec_())
As it says @Heike it seems that in windows it is necessary to add:
self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
Answered By - eyllanesc
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.