0
How to stop pop up menu from qt table horizontal header
Hi I have table view and displays column name using horizontal header. It works fine as Contextmenu policy was set as pop up menu and connect was set to display pop up menu. Question is related to stopping it dynamically. In other words , I need to stop displaying pop up menu( Or even stop user to right click on the header) when there are specific user input is set. Any way to achieve this ? I am very new to QT.
14 Respuestas
+ 2
Why don't you change the context menu policy of the horizontal header based on your user input conditions.
+ 2
Brother Ketan Lalcheta may be this is very helpful for you:
https://stackoverflow.com/questions/16317821/qt-remove-horizontal-header-of-table
+ 2
ok let me check
+ 2
Possible, but it might not be the most effective approach.
+ 2
You're welcome. Let me know if is it works?
+ 1
Then, instead of changing the context menu policy dynamically, you can intercept the context menu event and prevent it from being handled when your specific condition is met.
+ 1
Thanks a lot. I had tried this and it was working well for me.
My problem is that I don't want to hide entire header. It should display all the text as column header through horizontal header. But it should not pop up the right click context menu
+ 1
I can suggest you a way to do that by subclassing the header view and overriding the contextMenuEvent method to prevent the context menu from appearing. This will help you to keep the horizontal header visible but prevent the context menu from popping up when right-clicking on it. Check the comment section of the code how to implement in your QTableview:
https://sololearn.com/compiler-playground/cO3P2GGYFN7o/?ref=app
To get more details about your problem, this links will be very helpful:
1. https://doc.qt.io/qt-6/qcontextmenuevent.html
2. https://doc.qt.io/qt-6/qheaderview.html
3. https://doc.qt.io/qt-6/qobject.html
+ 1
Let me check. Many thanks again
0
I tried to set it to 0 , but it did not help.
Only catch I am doing is making it as pop up menu by default initially
If user input specific value, then changing it to 0. Does it work ? I tried but It is not working for me. Am I missing something?
0
I had tried setting clickable and selectable as false for horizontal header. But no success
0
Could you please elaborate more? I am new to QT and could not get you. It will be helpful if some sample code link is shared.
0
Is it good to disconnect all the signals on horizontal header ? Setting that also did not work for me
0
I do not have access to modify the c++ class or inherit it due to access across teams.
I just have access to python wrappers on C++ code and using the same for this requirement. So, cannot try with what you suggested in sample code.
Could not find anything specific from links you have shared as I already tried setting policy , but no success.
However, somehow contextmenu single on header is disconnected and it stopped working I.e. now it prevents poping up the context menu
Is this standard way or not ? Do you have anything else in mind for me to try apart from set policy and inheritance?
Many thanks for your extended hand of support on this