Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] QSplitterHandle does not emit customContextMenuRequested signal

[SOLVED] QSplitterHandle does not emit customContextMenuRequested signal

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 1.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Violet Giraffe
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • V Offline
        V Offline
        Violet Giraffe
        wrote on last edited by
        #3

        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!

        1 Reply Last reply
        0
        • Chris KawaC Offline
          Chris KawaC Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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 :)

          1 Reply Last reply
          0
          • V Offline
            V Offline
            Violet Giraffe
            wrote on last edited by
            #5

            :)
            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.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved