Important: Please read the Qt Code of Conduct -

[Solved] Problem clicking QPushButton with a menu

  • I made a custom widget in QT Designer. In this custom widget, I have a QPushButton. In my code, I make a menu for this button and set it using QPushButton::setMenu. I do this throughout my code in custom widgets that I wrote without Designer. For some reason, I have a problem with the widget that I made in Designer. In order to activate the button's menu, I have to click only on the right border of the button. If I click anywhere else within the button or its border, my click is not registered, but if I click on the right edge, the menu pops down as desired. Is this a known bug? Does anyone have any suggestions on how to fix this?

    I do not set any special style sheet on my button (left the styleSheet line in Designer blank), I do not have any other actions connected to this button. I did mark this as a "flat" button, but I tried it with and without the "flat" property checked in Designer and both ways give the same problem. The button only registers a click when I click on the right edge.

    Suggestions are appreciated!

  • This is not a bug, there is a problem in your code. Please post the relevant code so we can help.

  • I just found the problem and solution this morning.

    I was using a class written by a colleague and did not realize that it inherited QWidget in order to use winEvent. My object of that class was not being explicitly added to my form and so it was automatically placed at (0,0) and was covering my button. I fixed the problem by setting the size of the widget using setFixedSize(0,0).

    I understand that its helpful to post code when posting problems but its hard to determine the relevant code when my class using the ui had 5000 lines of code and was not doing anything explicitly to the button other than setting a menu on it. I guess my question was really how to go about investigating the problem because I had no idea what code was relevant to post!

  • Don't forget to add [solved] to your post

  • How do I mark it as solved? I assume I need to add a tag, but don't see where.

  • Sorry, guess it was already added.


  • Prefix the subject with [Solved]

    • in addition to tagging it at solved

Log in to reply