Solved How to add checkbox to context menu?
-
@JonB Thanks.
I googled for it of course, and I found the solutions you mention. Note that they inheritQWidgetAction
.
My solution is based on the first one, but I'm not sure if I've ported it to Python correctly.And yes, if I didn't have the requirement for tri-state I could simply use checkable menu actions.
-
@midnightdim
It helps if you reference where you got your code from when asking the question :)That code uses
setDefaultWidget(_widget);
, which @mrjj called your attention to. So don't you needself.setDefaultWidget(self.widget)
? Hmm, OK, I see he has just changed his comment. Your Python code looks equivalent to the C++ to me. I don't know, unless doing it withsetDefaultWidget()
is better. -
OH i miss some many thing with python.
in c++ the virtual function is like
https://doc.qt.io/qt-5/qwidgetaction.html#createWidgetQWidgetAction::createWidget(QWidget *parent)
but his is like
def createWidget(self,text):
return self.widgetso extra text with. WIll this still override the base version ? ( i guess not)
-
@mrjj
Yes, good spot, that does indeed look fluffy. Trouble with Python where you don't actually know whether you're overriding anything :(@midnightdim
(You could put aprint()
statement into your override to see if it's ever really called.) Follow that advice to change your override method. Or, I don't know, use thesetDefaultWidget()
like the C++ does instead. -
@JonB I actually tested it before, and yes, this override does get called. I'll try to change it to
setDefaultWidget()
. -
-
@midnightdim
Yes, I did wonder why you chose to adopt different code from that example! :) -
@JonB I'm not a pro programmer (started Python less than a year ago, have very small experience in C++) and the documentation for PySide6 doesn't look clear to me, also there were no examples for this particular case. So I wasn't sure about
setDefaultWidget
method in PySide6.
Thanks again. -
Hi,
add checkbox to context menu thorough the video link below
https://www.youtube.com/watch?v=TgDKcdC7X3E -
@danielcharles Why do you post a link to a video handling C#? This is Qt forum...