Problem on implement category choosing

Tags: I want to build a convenient ui for user to choose categories. Probably, one note has more than one category. At first, I try to put something like checkbox in the KMenu, so the menu shouldn’t close after being clicked. The standard way is put a KToggleAction or set KAction::setCheckable(). But they all would close the QMenu after being clicked.

Then I tried QCheckBox. It appeared in the up-left of menu, but only one is putted. QCheckBox requires a QWidget in constructor, so I can set it to QMenu. The QCheckBox can keep menu open after it was clicked, but I think there will be difficult to implement it well like this.

The qt-4.2 add a QWidgetAction. At first, I think using QWidgetAction can slove this. But later I realized the QWidgetACtion is still a action, and menu may still close after it send clicked signal to QWidgetAction.

Brade told me check QMenu’s code to find reason. I found the source of closing menu after a action was click, and trying to override the mouse event now. If I success, I may commit a update to KMenu. :-)

When I look into QMenu’s source code, I am feeling the power of Open Source….

If I failed, I will choose a traditional way : a category dialog.

Leave a Reply