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. Get focus on a popup
Forum Updated to NodeBB v4.3 + New Features

Get focus on a popup

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 2.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.
  • G Offline
    G Offline
    g1ennr
    wrote on last edited by
    #1

    In order to have a QPushButton with a down arrow I have used QPushButton.setMenu to add a dummy menu to the button. Then I show a popup (QWidget based custom widget) on the aboutToShow() signal of the dummy menu. This works except the popup does not get the focus and must be clicked twice, once for focus, once again to activate button on the popup. The focus appears to remain with the QPushButton as its appearance changes when I click in my popup widget.

    Is there a way that I can force the popup to get the focus when it is shown?

    I have tried setFocus() but that doesn't work. If I remove the menu from my button and open the popup from the clicked() signal then it works properly, but I don't want to do that unless I can somehow also have the same down arrow on the button that you get when you add a menu.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      ambershark
      wrote on last edited by
      #2

      That's weird. It should get focus when the widget is shown.

      Can you try with just a simple QLabel or QPushButton or something instead of your custom widget. So when you would normally show your custom widget show a QPushButton instead as a test and see if it gets focus.

      That will narrow down the problem on whether it's your custom widget or how it is being displayed.

      My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

      1 Reply Last reply
      0
      • G Offline
        G Offline
        g1ennr
        wrote on last edited by
        #3

        I tried what you suggested using a QPushButton and it turns out that the behaviour I am seeing is caused by setting the Qt::Popup flag. If I use Qt::FramelessWindowHint instead then the popup gets the focus on opening but doesn't close when another widget gets the focus. This is the same whether I use my custom widget or QPushButton.

        Also this is on OSX 10.8 with PyQt and Qt 5.2.1, in case that matters.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          ambershark
          wrote on last edited by
          #4

          Can I see the code where you open the popup?

          I've never used PyQt but it shouldn't really matter for what we're talking about here. And 5.2.1 is new enough for bug fixes and such. I have used popups with Qt 5.2.1 and OSX 10.9 and haven't seen this behavior.

          My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

          1 Reply Last reply
          0
          • G Offline
            G Offline
            g1ennr
            wrote on last edited by
            #5

            Here is a simple example that shows the problem:
            @
            import sys
            from PyQt5 import QtWidgets, QtGui
            from PyQt5.QtCore import Qt

            app = QtWidgets.QApplication(sys.argv)
            title = "Focus test"
            w = QtWidgets.QMainWindow()
            w.setWindowTitle(title)

            def onAboutToShow():
            p = QtWidgets.QPushButton(w)
            p.setText("A button")
            p.setWindowFlags(Qt.Popup)
            p.move(QtGui.QCursor.pos())
            p.show()

            b = QtWidgets.QPushButton()
            m = QtWidgets.QMenu()
            b.setMenu(m)
            m.aboutToShow.connect(onAboutToShow)

            w.setCentralWidget(b)
            w.show()
            app.exec_()
            @

            1 Reply Last reply
            0
            • A Offline
              A Offline
              ambershark
              wrote on last edited by
              #6

              I'll write some test code tomorrow and see if I can find out why this is happening. Don't have time to do it tonight. :)

              My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

              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