Issue
The QSplashScreen.showMessage()
method accepts an alignment flag i.e Qt.AlignLeft
. What is the syntax for setting both a horizontal and vertical alignment flag? All attempts yields "too many variables" error.
Solution
Qt::Alignment are QFlags that use bitwise operators &
, |
and ^
, in the case you want to combine flags you must use the |
operator, in the next part I show an example:
import random
from PyQt5 import QtCore, QtGui, QtWidgets
if __name__ == '__main__':
import sys
app = QtWidgets.QApplication(sys.argv)
pixmap = QtGui.QPixmap(640, 480)
h_alignments = (QtCore.Qt.AlignLeft, QtCore.Qt.AlignRight, QtCore.Qt.AlignHCenter, QtCore.Qt.AlignJustify)
v_alignments = (QtCore.Qt.AlignTop, QtCore.Qt.AlignBottom, QtCore.Qt.AlignVCenter, QtCore.Qt.AlignBaseline)
pixmap.fill(QtGui.QColor("green"))
w = QtWidgets.QSplashScreen(pixmap)
def on_timeout():
a = random.choice(h_alignments) | random.choice(v_alignments)
w.showMessage("Stack Overflow", alignment=a)
timer = QtCore.QTimer(interval=100, timeout=on_timeout)
timer.start()
QtCore.QTimer.singleShot(10*1000, QtWidgets.QApplication.quit)
w.show()
sys.exit(app.exec_())
Answered By - eyllanesc
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.