user896036
user896036

Reputation: 509

How to call qt mousepressevent explicitly?

I have a button class where i have used mouse press and release event. Suppose i want when i press a button another child window should open and until that child window is opened the button should be pressed state. How can i do it?

Upvotes: 1

Views: 1351

Answers (1)

Mat
Mat

Reputation: 206659

You shouldn't be using the mouse press/release events to detect actions on your buttons unless you have very specific needs, and don't care at all about keyboard actions and shortcuts. Use the clicked() signal.

To make your button stay depressed after a click, you should put your QPushButton to toggle button mode by calling setCheckable(true) when you construct it.

It will emit the clicked() signal when you press it like usual, but will stay in depressed state until either you click on it again, or you call setChecked(false); on it.

So, when you dismiss the popup window, simply uncheck the toggle button. (Or have the second click on that button, that will uncheck it, also dismiss the popup.)

Note: calling setChecked(bool) never triggers the clicked() signal. But it triggers the toggled(bool) if you need that.

Upvotes: 2

Related Questions