[SOLVED] QSplitterHandle does not emit customContextMenuRequested signal
-
I have 2 widgets layed out in a vertical splitter. I want to make it so that I can right-click the splitter and a context menu appears where I can select from a pre-set list of splitter positions (like 50/50, 25/75 etc.). Naturally, I've tried this:
@connect(ui->splitter->handle(1), SIGNAL(customContextMenuRequested(QPoint)), SLOT(splitterContextMenuRequested(QPoint)));@
But my slot is never called. Why is that, and how can I achieve what I want?
-
As the docs specify, to get that particular signal you need to set the context menu policy of the splitter to Qt::CustomContextMenu.
The other thing is that this signal is emitted by the splitter object, not the splitter handle of it. -
The splitter object itself emits this signal no problem, BUT it is emitted no matter where I click. However, setting the custom context menu policy on the handle solved the problem. Thanks!
-
Sure. You can get the handle geometry and check if the click occurs inside, eg.
@
void SomeClass::splitterClickSlot(QPoint p){
auto geometry = ui->splitter->handle(1)->geometry();
if(geometry.contains(p))
//do stuff...
});
@Edit. Oh, your way is better :)
-
:)
I always forget to set CustomContext policy. This isn't the first time I'm being puzzled as to why my menu isn't showing up. Frankly, I don't understand why that's not the default value.