samedi 18 avril 2015

How to create a button with a key shortcut label on it?


Vote count:

0




I'm writing a Python and PyQt5 program for people who prefer to use the keyboard rather than the mouse (e.g. Emacs users). I think it would be useful for some buttons to display the key shortcut that executes their action, like this:


Mock-up of buttons with key shortcuts written on them


One way to achieve this seems to be to subclass QPushButton, override its paintEvent method, use QPushButton's painting and then draw over it with QPainter.drawRoundedRect and QPainter.drawText. However, I'm new to Qt and have some questions:



  1. Is this the best way?

  2. To create a "professional" widget, what other methods should I override? sizeHint, minimumSizeHint, some others?

  3. How to draw a QPushButton with its text and icon off-center, so that when I paint the key shortcut over it, it'll be the right size and centered?



asked 16 secs ago

Pkkm

133






How to create a button with a key shortcut label on it?

Aucun commentaire:

Enregistrer un commentaire