Search code examples
raspberry-pipyqt4qt4x11

Qt4 WindowsStayOnTop on LXSession


I'm running an application on raspberry pi which uses qt4. My application have different windows, main window and dialogues. When I run my application on raspberry pi desktop it works fine, Dialog doesn't end up behind main window if i click on main window.

Qt.WindowStaysOnTopHint works fine. Qt.WindowStaysOnTopHint Makes sure that the window is on top of Main Window and don't end up behind not being able to access it.

When I run my application on lxsession autostart the

Qt.WindowStaysOnTopHint

tool doesn't work...

Any idea how it can be resolved?

What I have done so far is calling

Dialog.setWindowFlags(Qt.WindowStaysOnTopHint|Qt.X11BypassWindowManagerHint) 

It kinda works but the dialog is frameless.

class Ui_MainWindow(object):

  def setupUi(self, MainWindow):
       MainWindow.setObjectName(_fromUtf8("MainWindow"))
       MainWindow.resize(800, 480)
       MainWindow.setMinimumSize(QtCore.QSize(800, 480))
       MainWindow.setMaximumSize(QtCore.QSize(800, 480))
       MainWindow.setWindowFlags(Qt.FramelessWindowHint)

class ControlMainWindow(QtGui.QMainWindow):

   def __init__(self, parent=None):
      super(ControlMainWindow, self).__init__(parent)
      self.ui = Main_Window.Ui_MainWindow()
      self.ui.setupUi(self)

Above is my Main window setup

Below is my Dialog setup, which Im calling from MainWindow to show.

class Ui_Dialog(object):

   def setupUi(self, Dialog):

    Dialog.setObjectName(_fromUtf8("Dialog"))
    Dialog.resize(492, 200)
    Dialog.setMinimumSize(QtCore.QSize(492, 200))
    Dialog.setMaximumSize(QtCore.QSize(492, 200))
    Dialog.setWindowFlags(Qt.WindowStaysOnTopHint)


class ControlMainDialog(QtGui.QDialog):

def __init__(self, parent=None):
    super(ControlMainDialog, self).__init__(parent)

    self.ui = Ui_Dialog()
    self.ui.setupUi(self)

I'm doing set parent in Dialog or ControlMainDialog as:

Dialog.setParent(Qt.QMainWindow) 

It's not correct, any idea?


Solution

  • I managed to solve the issue, it's actually well documented here [https://doc.qt.io/qt-5/qdialog.html#modal-dialogs]. I was using modeless Dialog by calling show() when i wanted to show my window, this allowed me to access other window and making the dialog falling behind main window, which was my issue. Using Modal dialog is showing dialog using exec(), which is explained as following:

    When an application modal dialog is opened, the user must finish interacting with the dialog and close it before they can access any other window in the application