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] QShortcut to slotToggleInspector
Qt 6.11 is out! See what's new in the release blog

[SOLVED] QShortcut to slotToggleInspector

Scheduled Pinned Locked Moved General and Desktop
9 Posts 3 Posters 3.6k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    The web demo has a file menu which I've hidden. I want to replace the menu item to call @slotToggleInspector(bool)@ into a keyboard shortcut.

    So I tried this, @new QShortcut(Qt::Key_F2, this, SLOT(slotToggleInspector(true)));@ however this doesn't get called. Doing the same thing but for @Qt::Key_F1@ and calling @slotAboutApplication@ works fine. No errors.

    Ideas?

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      Anybody?

      This has really been bothering me and I still can't figure it out.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on last edited by
        #3

        The only thing I can think of, is that something else is already using that shortcut (system perhaps), which is interfering with you doing the same.

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          [quote author="Andre" date="1333106992"]The only thing I can think of, is that something else is already using that shortcut (system perhaps), which is interfering with you doing the same. [/quote]
          I thought this would be the case, however I've tried a whole bunch of shortcuts. I swapped ones that did work and they stopped working with that slot.

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

            @
            new QShortcut(Qt::Key_F2, this, SLOT(slotToggleInspector(true)));

            @
            Ah, I note the error. What is the 'true' doing there? That is not allowed! This should give a warning at runtime...

            You should connect to a slot that does not take any arguments instead. I would use QAction in between your shortcut and the actual action as an abstraction. You connect your shortcut to the toggle() slot of QAction, and then use the toggeled(bool) signal to do the actual work. The action can also be put on a toolbar or in a menu or something like that.

            1 Reply Last reply
            0
            • D Offline
              D Offline
              dbzhang800
              wrote on last edited by
              #6

              Yes, but IMO, the following statement should have given a warning when the application running, tells that the slot doesn't exists.
              @
              new QShortcut(Qt::Key_F2, this, SLOT(slotToggleInspector(true)));
              @

              1 Reply Last reply
              0
              • ? Offline
                ? Offline
                A Former User
                wrote on last edited by
                #7

                Sorry for the late reply, I've been working on a few other things.

                I noticed the error with the @true@ statement being in the code. I removed that promptly. I'll try the QAction method and see where that takes me.

                1 Reply Last reply
                0
                • ? Offline
                  ? Offline
                  A Former User
                  wrote on last edited by
                  #8

                  Ah, now... My shortcut works when I have the File/Edit menu visible. If I hide it, my shortcut no longer works. Is there a way to avoid this behaviour?

                  1 Reply Last reply
                  0
                  • ? Offline
                    ? Offline
                    A Former User
                    wrote on last edited by
                    #9

                    I solved it by not needing the @toggle@ argument. Win!

                    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