-1

Or just text in it. Is it possible?

I found implementation with paintEvent How to rotate a QPushButton?, but it's not very 'pythonic' in my opinion.

Community
  • 1
  • 1
JogSottot
  • 1
  • 1

1 Answers1

1

I'm not sure you can, but it's possible to emulate the effect by using a mask over a button and emulating the foreground with a bitmap. For example:

    import sys
    from PyQt5 import QtCore, QtGui, QtWidgets

    class MyFrame(QtWidgets.QFrame):
        def __init__(self, parent=None,initials=None):
            QtWidgets.QFrame.__init__(self, parent)
            self.btn = QtWidgets.QPushButton(self)
            self.btn.setIcon(QtGui.QIcon('rotatedBitmap.png'))
            self.btn.setMask(QtGui.QBitmap('rotatedBitmapMask.png'))
            self.btn.setIconSize(QtCore.QSize(156,166))
            self.btn.move(30,30)
            self.btn.resize(156,166)
            self.btn.clicked.connect(self.printthis)

        def printthis(self):
            print('this')

    if __name__ == '__main__':
        app = QtWidgets.QApplication(sys.argv)
        Frame = MyFrame(None)
        Frame.resize(720,600)
        Frame.show()
        app.exec_()

This was a fast example and I'm not sure if I can use use the same bitmap strictly as both Foreground and Mask (in fact I'm not sure about the rules for the mask) but it should work. Use the following image as test.

Rotated Pixmap for a button

and the following as Mask.

enter image description here

armatita
  • 12,825
  • 8
  • 48
  • 49