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. Popup and focus Issue

Popup and focus Issue

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

    hi
    Following is my code
    in clsFarmers, I popup a window of type clsPopUpVillageList
    with QtCore.Qt.ApplicationModal on focus of lineEdit control (txtVillage)

    1. I am not getting modal window
    2. When I close the pop with escape Key The focus doesnt come to txtVillage, instead it goes some where else.

    kindly help

    -----------------------------------------------------------------------------
    class clsPopUpVillageList(QtWidgets.QWidget, Ui_Widget1):
        def __init__(self,parent=None):
                super().__init__(parent)          
                self.setupUi(self)               
                self.installEventFilter(self)            
                self.move(300, 100)
                self.txtSearch.setFocus()
                self.windowFlags = QtCore.Qt.ApplicationModal
        def eventFilter(self, obj, event):   
            if event.type() ==QtCore.QEvent.KeyPress:
                print('clsPopUpVillageList')
                if (event.key() == QtCore.Qt.Key_Escape):                    
                    self.close()                    
                    return False
            print('return--pop')                
            return super(clsPopUpVillageList, self).eventFilter(obj, event)
    
    -------------------------------------------------------------------------
    -------------------------------------------------------------------------
    class clsFarmers(QtWidgets.QWidget, Ui_Widget):
        def __init__(self,parent=None):
            super().__init__(parent)       
            self.setupUi(self)      
            self.txtName.installEventFilter(self)
            self.txtAdd1.installEventFilter(self)
            self.txtAdd2.installEventFilter(self)
            self.txtVillage.installEventFilter(self)
            self.txtMobile.installEventFilter(self)
    
            
        def eventFilter(self, obj, event):  
            if (event.type() ==QtCore.QEvent.FocusIn):
                print('focus')
                if (obj == self.txtVillage):                       
                    o = clsPopUpVillageList(self)
                    o.setWindowModality(QtCore.Qt.ApplicationModal)
                    o.show()
                    print('focus-----------')
                    return False            
            elif (event.type() == QtCore.QEvent.KeyPress) :
                print('key press:', (event.key(), event.text()))
                if ((event.key() == QtCore.Qt.Key_Enter) or (event.key() == QtCore.Qt.Key_Down)):
                    if ((obj == self.txtName) or (obj == self.txtAdd1) or (obj == self.txtAdd2) or (obj == self.txtVillage) or (obj == self.txtMobile)):
                        print("txtVillage key")
                        k = QtGui.QKeyEvent(QtCore.QEvent.KeyPress, QtCore.Qt.Key_Tab, QtCore.Qt.NoModifier)                     
                        QtCore.QCoreApplication.sendEvent(obj, k)              
                        return False
                elif ((event.key() == QtCore.Qt.Key_Enter) or (event.key() == QtCore.Qt.Key_Up)):
                    if ((obj == self.txtName) or (obj == self.txtAdd1) or (obj == self.txtAdd2) or (obj == self.txtVillage) or (obj == self.txtMobile)):
                        print("txtVillage key")
                        k = QtGui.QKeyEvent(QtCore.QEvent.KeyPress, QtCore.Qt.Key_Tab, QtCore.Qt.ShiftModifier)                     
                        QtCore.QCoreApplication.sendEvent(obj, k)              
                        return False
            print('return--main')
            return super(clsFarmers, self).eventFilter(obj, event)
    
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Shouldn't you rather use a QDialog for your popup ?

      In any case, if you want to set a window flag, use the setWindowFlag method.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1

      • Login

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