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. Newbie question, first mouse click ignored in submenu
QtWS25 Last Chance

Newbie question, first mouse click ignored in submenu

Scheduled Pinned Locked Moved Solved General and Desktop
groupboxsubmenu
17 Posts 2 Posters 4.8k Views
  • 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.
  • M Offline
    M Offline
    MikeP
    wrote on 5 Apr 2016, 09:50 last edited by
    #1

    The application has a main window with a menubar, some submenus are created using GroupBoxes and clickable Frames or Labels because the menu entries are graphical rather than textual.

    If the groupbox is made permanently visible when created then the first mouse-click within the group is always accepted. If the groupbox is not visible when created (the required state, as below) and made visible when required the first mouse-click within the group is always ignored.

    Any suggestions as to how to fix this?

    edited code (mnuColour and mnuOffset are created in the same manner as mnuWidth); -

    class Ui_measWindow(object):
    
        def setupUi(self, measWindow):
            measWindow.setObjectName(_fromUtf8("measWindow"))
            measWindow.resize(1026, 790)
            measWindow.setWindowTitle(_fromUtf8("Measure"))
            measWindow.setLocale(QtCore.QLocale(QtCore.QLocale.English, QtCore.QLocale.UnitedKingdom))
    
            self.centralwidget = QtGui.QWidget(measWindow)
            self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
            QtCore.QObject.connect(self.centralwidget, QtCore.SIGNAL(_fromUtf8("clicked()")), self.showHide)
    
            self.videoFrame = QtGui.QLabel(self.centralwidget)
            self.videoFrame.setGeometry(QtCore.QRect(0, 0, 1024, 768))
            self.videoFrame.setObjectName(_fromUtf8("videoFrame"))
    
            self.MainWindow = measWindow
    
    	# create width select submenu
            self.mnuWidth = QtGui.QGroupBox(self.centralwidget)
            self.mnuWidth.setGeometry(QtCore.QRect(20, 0, 60, 180))
            self.mnuWidth.setAutoFillBackground(True)
            self.mnuWidth.setTitle(_fromUtf8(""))
            self.mnuWidth.setAlignment(QtCore.Qt.AlignCenter)
            self.mnuWidth.setFlat(False)
            self.mnuWidth.setObjectName(_fromUtf8("mnuWidth"))
            self.mnuWidth.setVisible(False)
            for i in range (1, 9):
                lName = 'line_'+str(i)
                lineWid = wids[i-1]
                self.lName = extQFrame.extQFrame(self.mnuWidth)
                self.lName.setGeometry(QtCore.QRect(10, 20*i, 40, 16))
                self.lName.setFrameShadow(QtGui.QFrame.Plain)
                self.lName.setLineWidth(lineWid)
                self.lName.setMidLineWidth(0)
                self.lName.setFrameShape(QtGui.QFrame.HLine)
                self.lName.setFrameShadow(QtGui.QFrame.Plain)
                self.lName.setObjectName(_fromUtf8(lName))
                QtCore.QObject.connect(self.lName, QtCore.SIGNAL(_fromUtf8("clicked()")), self.btnClicked)
    
    	blah, blah...
    
            measWindow.setCentralWidget(self.centralwidget)
            self.menubar = QtGui.QMenuBar(measWindow)
            self.menubar.setGeometry(QtCore.QRect(0, 0, 1024, 25))
            self.menubar.setContextMenuPolicy(QtCore.Qt.PreventContextMenu)
            self.menubar.setObjectName(_fromUtf8("menubar"))
    
    	# create width select top menu
            self.menuLine_width = QtGui.QMenu(self.menubar)
            QtCore.QObject.connect(self.menuLine_width, QtCore.SIGNAL(_fromUtf8("aboutToShow()")), self.showHide)
            self.menuLine_width.setObjectName(_fromUtf8("menuLine_width"))
    
    	blah, blah...
    
        def hideAll(self):
            self.mnuWidth.setVisible(False)
            self.mnuColour.setVisible(False)
            self.mnuOffset.setVisible(False)
    
        def showHide(self):
    	# hide all, then show required menu
    	self.hideAll()
            menuID = self.MainWindow.sender().objectName()
            if menuID.endsWith('width') == True:
                self.mnuWidth.setVisible(True)
                self.mnuWidth.activateWindow()	# added to see if it helps, doesn't
            elif menuID.endsWith('colour') == True:
                self.mnuColour.setVisible(True)
                self.mnuColour.activateWindow()
            elif menuID.endsWith('Offset') == True:
                self.mnuOffset.setVisible(True)
                self.mnuOffset.activateWindow()
    
        def btnClicked(self):
    	# menu item clicked, process and action
            global lWidth, lColour, mOffset
            buttonID = self.MainWindow.sender()
            pName = buttonID.objectName()
            pNum = num.search(pName)
            pNum = int(pNum.group())
    
            if pName.startsWith('line') == True:
                lWidth = pNum-1
            elif pName.startsWith('col') == True:
                lColour = pNum-1
            elif pName.startsWith('off') == True:
                mOffset = pNum-1
    
    	# clear menus & update display
    	self.hideAll()
            self.showChange()
    
    
    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 5 Apr 2016, 10:11 last edited by
      #2

      hi and welcome
      Just a thought.
      When u make it visible,
      call setFocus on it and see if then
      first click works?

      M 1 Reply Last reply 5 Apr 2016, 10:41
      0
      • M mrjj
        5 Apr 2016, 10:11

        hi and welcome
        Just a thought.
        When u make it visible,
        call setFocus on it and see if then
        first click works?

        M Offline
        M Offline
        MikeP
        wrote on 5 Apr 2016, 10:41 last edited by
        #3

        @mrjj Tried that, it was in the code after the .activateWindow but didn't have any effect.

        M 1 Reply Last reply 5 Apr 2016, 10:45
        0
        • M MikeP
          5 Apr 2016, 10:41

          @mrjj Tried that, it was in the code after the .activateWindow but didn't have any effect.

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 5 Apr 2016, 10:45 last edited by
          #4

          @MikeP
          Hmm. After it been shown first time, it will work all the time then ?
          Even if u click outside app and then directly to menu ?

          M 2 Replies Last reply 5 Apr 2016, 11:28
          0
          • M mrjj
            5 Apr 2016, 10:45

            @MikeP
            Hmm. After it been shown first time, it will work all the time then ?
            Even if u click outside app and then directly to menu ?

            M Offline
            M Offline
            MikeP
            wrote on 5 Apr 2016, 11:28 last edited by
            #5

            @mrjj Yup!

            M 1 Reply Last reply 5 Apr 2016, 11:37
            0
            • M mrjj
              5 Apr 2016, 10:45

              @MikeP
              Hmm. After it been shown first time, it will work all the time then ?
              Even if u click outside app and then directly to menu ?

              M Offline
              M Offline
              MikeP
              wrote on 5 Apr 2016, 11:34 last edited by
              #6

              @mrjj Sorry, not entirely sure but I think clicking outside the app doesn't affect what happens when you come back to the menu providing the menu is still displayed. After a valid click the menu is hidden anyway and whenever it is re-displayed the first click is ignored.

              1 Reply Last reply
              0
              • M MikeP
                5 Apr 2016, 11:28

                @mrjj Yup!

                M Offline
                M Offline
                mrjj
                Lifetime Qt Champion
                wrote on 5 Apr 2016, 11:37 last edited by
                #7

                @MikeP said:
                hmm. it does sounds like a focus problem on initial show.

                You could try to create it visible and then override
                showEvent for mainwindow
                and there hide it.
                ( so when mainwin shows, it is still hidden)

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 5 Apr 2016, 11:38 last edited by
                  #8

                  oh
                  so it will do the same if hidden and shown again ?

                  M 1 Reply Last reply 5 Apr 2016, 11:47
                  0
                  • M mrjj
                    5 Apr 2016, 11:38

                    oh
                    so it will do the same if hidden and shown again ?

                    M Offline
                    M Offline
                    MikeP
                    wrote on 5 Apr 2016, 11:47 last edited by
                    #9

                    @mrjj Yes

                    M 1 Reply Last reply 5 Apr 2016, 11:52
                    0
                    • M MikeP
                      5 Apr 2016, 11:47

                      @mrjj Yes

                      M Offline
                      M Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on 5 Apr 2016, 11:52 last edited by
                      #10

                      @MikeP said:
                      Ok, sorry cant explain.
                      QGroupBox must steal first click to focus.

                      What widgets do u put in this QGroupBox ?

                      M 1 Reply Last reply 5 Apr 2016, 11:58
                      0
                      • M mrjj
                        5 Apr 2016, 11:52

                        @MikeP said:
                        Ok, sorry cant explain.
                        QGroupBox must steal first click to focus.

                        What widgets do u put in this QGroupBox ?

                        M Offline
                        M Offline
                        MikeP
                        wrote on 5 Apr 2016, 11:58 last edited by
                        #11

                        @mrjj They are slightly modified QFrames or QLabels, the modification being to add the 'clicked' signal to the original. But setting the focus to the QGroupBox had no effect on the problem.

                        M 1 Reply Last reply 5 Apr 2016, 12:07
                        0
                        • M MikeP
                          5 Apr 2016, 11:58

                          @mrjj They are slightly modified QFrames or QLabels, the modification being to add the 'clicked' signal to the original. But setting the focus to the QGroupBox had no effect on the problem.

                          M Offline
                          M Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on 5 Apr 2016, 12:07 last edited by
                          #12

                          @MikeP
                          Hmm I tried with
                          https://wiki.qt.io/Clickable_QLabel
                          Which sounds like what you have but
                          show/hiding the QGroupBox did not eat first click.

                          I think we need a fellow Python user to find this :)
                          seems not to happen in c++- well not in my sample anyway.

                          M 1 Reply Last reply 5 Apr 2016, 13:08
                          0
                          • M mrjj
                            5 Apr 2016, 12:07

                            @MikeP
                            Hmm I tried with
                            https://wiki.qt.io/Clickable_QLabel
                            Which sounds like what you have but
                            show/hiding the QGroupBox did not eat first click.

                            I think we need a fellow Python user to find this :)
                            seems not to happen in c++- well not in my sample anyway.

                            M Offline
                            M Offline
                            MikeP
                            wrote on 5 Apr 2016, 13:08 last edited by
                            #13

                            @mrjj I have found that, once the menu is displayed, if I click in the main window before clicking in the menu then the click on the menu is accepted. Unfortunately I don't have enough experience of Python to know where to go next, I'll keep trying odds and sods in the meantime.

                            1 Reply Last reply
                            0
                            • M Offline
                              M Offline
                              mrjj
                              Lifetime Qt Champion
                              wrote on 5 Apr 2016, 13:11 last edited by
                              #14

                              It really sounds like it just dont have
                              focus. but it should.
                              Well im even bigger python noob :)

                              M 1 Reply Last reply 6 Apr 2016, 15:04
                              0
                              • M mrjj
                                5 Apr 2016, 13:11

                                It really sounds like it just dont have
                                focus. but it should.
                                Well im even bigger python noob :)

                                M Offline
                                M Offline
                                MikeP
                                wrote on 6 Apr 2016, 15:04 last edited by
                                #15

                                @mrjj Using focusChanged I have determined that, when the mouse clicks on the menubar the focus is given to the menubar object, as expected and the QGroupBox is displayed. If I do not deliberately setFocus to the QGroupBox then the first click in the QGroupBox removes the focus from the menubar to None. Subsequent clicks in the QGroupBox set the focus to the menubar, the click is processed and the focus goes back to None. If I deliberately setFocus to the QGroupBox then focus transfers to the QGroupBox, then the first click in the QGroupBox removes the focus from the QGroupBox but is not processed. Subsequent clicks in the QGroupBox set the focus to the QGroupBox, the click is processed and the focus goes back to None!

                                1 Reply Last reply
                                0
                                • M Offline
                                  M Offline
                                  MikeP
                                  wrote on 12 Apr 2016, 07:03 last edited by
                                  #16

                                  Sidestepped the problem by substituting a toolbar for the menubar!

                                  M 1 Reply Last reply 12 Apr 2016, 07:36
                                  1
                                  • M MikeP
                                    12 Apr 2016, 07:03

                                    Sidestepped the problem by substituting a toolbar for the menubar!

                                    M Offline
                                    M Offline
                                    mrjj
                                    Lifetime Qt Champion
                                    wrote on 12 Apr 2016, 07:36 last edited by
                                    #17

                                    @MikeP
                                    good workaround.

                                    1 Reply Last reply
                                    0

                                    10/17

                                    5 Apr 2016, 11:52

                                    • Login

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