Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Pyside2 - While QCombobox is opened, click on gui sends gui to back and focus on other window, in windows 10



  • If I run the sample code below on windows 10,Ubuntu, and Centos6 in a python3.7/ Pyside2(5.13.1) env (built with anaconda), I get different focus behavior with the QCombobox. It seems to work correctly in Linux but in windows 10 if I click a Qcombobox and display the items, then click on the gui out side of the combobox items, the focus is lost and the gui is sent to the back of any other windows open.

    Is there anything on the windows side that might be triggering this? Ideally I dont want to brute force the windowsFlag always on top hint, just for windows 10... Any help greatly appreciated

    from PySide2 import QtWidgets
    
    class MyWindow(QtWidgets.QMainWindow):
    
        def __init__(self):
            super(MyWindow, self).__init__()
            self.edit = QtWidgets.QComboBox()
            self.edit.addItems(['item1', 'item2', 'item3'])
            layout = QtWidgets.QHBoxLayout()
            layout.addWidget(self.edit)
            w = QtWidgets.QWidget()
            w.setLayout(layout)
            self.setCentralWidget(w)
    
    if __name__ == '__main__':
    
        app = QtWidgets.QApplication(sys.argv)
        window = MyWindow()
        window.show()
        sys.exit(app.exec_())
    

  • Banned

    Okay I would actually say what is occurring in Linux (as you describe the descrepancy) is actually incorrect behavior as is not setting the current focus properly.

    I ran this example on Windows 10 and when using 2 monitors if I click outside the ComboWindow on a different Monitor the ComboWindow simply loses focus and does what I would expect it to do when it loses focus however if I click on something within the same monitor as ComboWindow windows brings that other window to the front and the ComboWindow drops back one layer which means if I were to minimize the current window the ComboWindow would now be on top (which it was). This is normal window behavior unless you stress you want your window to always be on top.

    I would ask (if I understood you correctly) why is Linux not doing this? The OS has no reason to keep ComboWindow on top when you click on another window and it should bring that other window to the fore-front pushing ComboWindow back one layer



  • @Denni-0
    Thanks for taking a look at the sample.
    Actually the gui (QMainWindow) is whats being clicked once the combo box is opened, so I would think the QMainWindow should still be on top of any other windows below it. So clicking any where on the QMainWindow other than the combobox sends it back.


  • Lifetime Qt Champion

    @alom I think the behaviour you're describing on Windows and Linux are simply OS preferences. On Windows the Window you're clicking on is raised even if the current window has an "open" combo box. On Linux only the combo box is closed on first click outside of the window. I would not to try to change this as users are used to the behaviour of their systems.



  • Sorry I don't think I'm explaining myself well, I'm still clicking on the qt window if i don't select a combobox item . No other windows application will send it back if your still clicking on the application.


  • Lifetime Qt Champion

    @alom Sorry, I don't really understand: on Windows 10 you start you app and then do what exactly and what exactly happens?



  • qcombox_focus (1).gif


  • Lifetime Qt Champion

    @alom I can't reproduce this on my Windows 10 machine.
    Is it the same if you start your app outside of the IDE?



  • OK good to know you are not experiencing it, yep the behavior is still happening running from a bat file.

    Maybe something is on my box...I cant think of anything that might be triggering this. I don't have a clean windows install to start debugging. The only thing I can see might be an issue is my wacom tablet and turning off windows ink features?


  • Lifetime Qt Champion

    @alom You could create another user account and check whether it's the same.



  • Thanks good idea, unfortunately its the same :/
    Is it possibly this might be from the anaconda build? I'm using conda to manage all my envs, just throwing ideas around at this point


  • Banned

    Okay @alom like @jsulm I cannot reproduce what you are experiencing either and yeah that is wrong operation of a window. Did you try minimizing your IDE window and see if it hides behind perhaps an open folder or something? Otherwise I took your MUC (Minimal Usable Code) and mucked around with it making it more Pythonic-PyQt-ish and while I am using PyQt5 you could just change PyQt5 to PySide2 and everything should still work the same. I just thought you might like to see a version of this sort. If you have any questions about my changes do ask there are reasons for everyone of them and I am perfectly fine with explaining those whys

    from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget
    from PyQt5.QtWidgets import QHBoxLayout, QComboBox
    
    class CentralPanel(QWidget):
        def __init__(self, parent):
            QWidget.__init__(self)
            self.Parent = parent
    
            self.cbxEdit = QComboBox()
            self.cbxEdit.addItems(['item1', 'item2', 'item3'])
    
            HBox = QHBoxLayout()
            HBox.addWidget(self.cbxEdit)
    
            self.setLayout(HBox)
    
    class MyWindow(QMainWindow):
        def __init__(self):
            QMainWindow.__init__(self)
    
            self.CenterPane = CentralPanel(self)
            self.setCentralWidget(self.CenterPane)
     
    if __name__ == '__main__':
        MainEventThread = QApplication([])
    
        MainApp = MyWindow()
        MainApp.show()
    
        MainEventThread.exec()
    
      # If anyone wants more extensive free help I run an online lab-like classroom-like 
      # message server feel free and drop by you will not be able to post until I clear 
      # you as a student as this prevents spammers so if interested here is the invite
      # https://discord.gg/3D8huKC
    


  • thanks, so I was able to get another windows 10 box and was not able to reproduce this behavior either with the same IDE and env.
    Unfortunately there is something on my workstation causing this...

    I did find another consistent behavior on my workstation with this issue. After the first click once the gui goes behind another window, if you try again, the windows stays on top as expected. So it's only on the first click out side a opened combo box, very strange.


Log in to reply