2

I'm trying to create a custom button, derived from "QAbstractbutton". I have overridden the paintEvent. However, my button is not visible in my widget. What I see is that the paintEvent is not getting called even after calling update/repaint/show on my button. What could be the missing link here?

Thanks!

Daniel Hedberg
  • 5,677
  • 4
  • 36
  • 61
mots_g
  • 637
  • 8
  • 27
  • include some example code please, e.g. code snippet of where you add your custom button to your widget, etc – Lars Jul 19 '10 at 14:00

1 Answers1

3

paintEvent on an object won't be called unless the object has a non-zero width and height. My guess (and absent any example code, it is a pure guess) is that you've just created one with a 0 width or height, and are expecting it to draw.

Caleb Huitt - cjhuitt
  • 14,785
  • 3
  • 42
  • 49
  • Thanks, this worked!I did not know qt optimises on paintEvent() in this case. When my class was derived from QWidget, paintEvent() would work properly(even with not size set initially). For this case(QAbstractbutton derived), I had to set some width and height in the constructor to get it working! – mots_g Jul 20 '10 at 04:59
  • 3
    Just simply reimplement sizeHint in your custom button and calculate proper size for data contained in button – Kamil Klimek Jul 20 '10 at 14:39