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.

29th Apr 2024, 5:13 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
14 Respuestas
+ 2
Why don't you change the context menu policy of the horizontal header based on your user input conditions.
29th Apr 2024, 6:47 PM
`ᴴᵗᵗየ
`ᴴᵗᵗየ - avatar
30th Apr 2024, 6:14 AM
`ᴴᵗᵗየ
`ᴴᵗᵗየ - avatar
+ 2
ok let me check
30th Apr 2024, 6:22 AM
`ᴴᵗᵗየ
`ᴴᵗᵗየ - avatar
+ 2
Possible, but it might not be the most effective approach.
30th Apr 2024, 6:25 AM
`ᴴᵗᵗየ
`ᴴᵗᵗየ - avatar
+ 2
You're welcome. Let me know if is it works?
30th Apr 2024, 6:48 AM
`ᴴᵗᵗየ
`ᴴᵗᵗየ - avatar
+ 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.
29th Apr 2024, 6:57 PM
`ᴴᵗᵗየ
`ᴴᵗᵗየ - avatar
+ 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
30th Apr 2024, 6:21 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
+ 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
30th Apr 2024, 6:38 AM
`ᴴᵗᵗየ
`ᴴᵗᵗየ - avatar
+ 1
Let me check. Many thanks again
30th Apr 2024, 6:46 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
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?
29th Apr 2024, 6:52 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
0
I had tried setting clickable and selectable as false for horizontal header. But no success
29th Apr 2024, 6:54 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
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.
30th Apr 2024, 6:12 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
0
Is it good to disconnect all the signals on horizontal header ? Setting that also did not work for me
30th Apr 2024, 6:23 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
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
30th Apr 2024, 8:57 AM
Ketan Lalcheta
Ketan Lalcheta - avatar