PyQt Window Focus

25,407

To get window_b to always stay on top you have to add the windowflag QtCore.Qt.WindowStaysOnTopHint. In your __init__ add the call

self.setWindowFlags(PyQt4.QtCore.Qt.WindowStaysOnTopHint)

I have to add that this only is a hint to the windowing manager and not guaranteed to succeed.

Share:
25,407
Uahmed
Author by

Uahmed

Currently, I am writing my Master's Thesis in the field of Blockchain Technology. I am working on “Design and Implementation of Decentralized Student Loan Management System using Smart Contracts and Blockchain Technology.” In the thesis, I am studying in depth about the blockchain technology,hyper ledger framework and Smart Contract. I am using Ethereum Blockchain and Solidity/Go language to develop Smart Contract. I will also be making the "dApp" to interact with the blockchain.

Updated on July 18, 2021

Comments

  • Uahmed
    Uahmed almost 3 years

    I am trying to give focus to a window if the user clicks on another window.

    Right now i have two windows: Window A is behind, and Window B is in front. When Window B appears, it disables Window A. Now what i want is that whenever the user clicks outside of Window B, it should give focus back to Window B.

    Here is the code for Window B:

    class window_b(QtGui.QDialog):
        def __init__(self,parent=None):
            super(window_b, self).__init__(parent)
            window_a.setEnabled(False)
            self.ui = Ui_Form_window_b()
            self.ui.setupUi(self)
            self.setFocusPolicy(QtCore.Qt.StrongFocus)
    
        def focusOutEvent(self,event):
            self.setFocus(True)
            self.activateWindow()
            self.raise_()
            self.show()
    

    I tried setFocus and activateWindow, but it didnt give focus back to Window B.

    Any suggestions?

  • Uahmed
    Uahmed over 11 years
    it works for me but it didnt give focus back to window_b now window_b remains always top but no focus .
  • halex
    halex over 11 years
    @user1224233 Ah ok. I read always in focus but my brain made always on top of it :). Sorry
  • Uahmed
    Uahmed over 11 years
    any suggestion to give focus to window ?
  • Ophir Carmi
    Ophir Carmi over 3 years
    where in the code in the question do we need to put the line you posted for the problem in the question to be solved?