Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Pushbutton promoted from QPushButton is invisible



  • I promoted a QPushButton in QtDesigner to myPushButton.

    I created myPushButton.h and myPushButton.cpp

    The ui_mainwindow.h file shows an object myPushButton being instantiated just like all the other QPushButtons. The constructor for myPushButton is the same in ui_mainwindow.h as all the normal QPushButtons. This all compiles correctly.

    When I run my application, myPushButton is invisible.

    But I can mouse over myPushButton and click the mouse, and the expected behavior occurs, i.e. myPushButton is clicked as expected. I have a text output signal that writes to a log window, and I see the correct text message when the myPushButton is pressed.

    So everything seems to work fine, the button is there in the layout, but the button is invisible.

    Does anyone understand why this happens? Do subclassed/promoted widgets need some sort of special display information to become visible?

    Thanks for any help.


  • Qt Champions 2019

    Did you overwrite the paint() event? Or why did you derive from QPushButton?



  • Thanks for your question, it led me to the solution!

    I derived from QPushButton because I'm porting to a touch screen on an embedded system, and I need to override QPushButton's "event" member function to process touch events properly.

    If the event type is not a touch panel event, I pass the event to the base class QPushButton.

    I was capturing "spontaneous" events (which include the paint event), and not passing them to the base class.

    So I removed the section that captured the spontaneous event, and things work as expected now.

    Thanks so much for taking the time to respond on a weekend. Kudos to you!



  • @JJLee said in Pushbutton promoted from QPushButton is invisible:

    it led me to the solution!

    great! so please don't forget to mark your post as solved then.