0

I have an issue with setting focus on one of four child windows from a main window. I tried setFocus to one of the four, but the main window still keeps the focus. I have a combo box that lets you choose which of the four windows to bring into focus. Each of the widows is on a separate monitor.

from PyQt4 import QtGui, QtCore
import numpy as np
from ui_GuiMask import Ui_MainWindow



class MainWindow(QtGui.QMainWindow):
    def __init__(self, parent = None):
    QtGui.QMainWindow.__init__(self, parent)
    QtGui.QWidget.__init__(self, parent)
    self.ui = Ui_MainWindow()
    self.ui.setupUi(self)

QtCore.QObject.connect(self.ui.cb_projectorSelector, QtCore.SIGNAL("currentIndexChanged(int)"), self.setProjectorFocus)


self.maskProjector_1 = MaskWindow(screen = 0)
self.maskProjector_1.show()
self.maskProjector_2 = MaskWindow(screen = 0)
self.maskProjector_2.show()


def setProjectorFocus(self):

whichProj = self.ui.cb_projectorSelector.currentIndex()
if whichProj == 0:              
    self.maskProjector_1.setFocus(True)
    self.maskProjector_2.setFocus(False)

elif whichProj == 1:                
    self.maskProjector_1.setFocus(False)
    self.maskProjector_2.setFocus(True)

shouldn't the focus activate one of the windows and move it to front ?

Dave
  • 41
  • 4

1 Answers1

0

Docs for setFocus() (Emphasis added):

void QWidget::setFocus ( Qt::FocusReason reason )

Gives the keyboard input focus to this widget (or its focus proxy) if this widget or one of its parents is the active window.

As I understand it, setFocus won't activate a top-level widget (window). It changes focus within the active window.

Use .activateWindow(), probably along with .raise().

Avaris
  • 35,883
  • 7
  • 81
  • 72