PyQt4: how to make undercorated window with reserved space
Asked Answered
C

3

0

I'd like to make a panel-like application using PyQt4 for Linux. for this i need the window i created:

  • to be undecorated
  • to have reserved space
  • to appear on all workspaces

From reading the documentation i've got the idea that i should use QtWindowFlags. But i have no clue as to how to do that. Also i believe there should be a Qt.WindowType hint somewhere telling the WM the window's a "dock" application. I have made this with pygtk following this thread, but here with Qt i don't really know how to handle this. (I need Qt for its ability to theme/skin application more easily.)

Below is the current code i made (nothing extraordinary).

import sys
from PyQt4 import QtGui

class Panel(QtGui.QWidget):
def __init__(self, parent=None): ## should the QtWindowFlag be here?
    QtGui.QWidget.__init__(self, parent) ## should the QtWindowFlag be there as well?

    self.setWindowTitle('QtPanel')
    self.resize(QtGui.QDesktopWidget().screenGeometry().width(), 25)
    self.move(0,0)

def main():
    app = QtGui.QApplication(sys.argv)
    panel = Panel()
    panel.show()
    sys.exit(app.exec_())
    return 0

if __name__ == '__main__':
    main()

Can anyone help me with this? Thanks :)

Concertgoer answered 29/4, 2011 at 8:7 Comment(0)
C
0

The solution is to use Python-Xlib, and it has been described in an answer on a universal way to reserve screen space on X.

Concertgoer answered 3/6, 2011 at 20:24 Comment(0)
B
5

Read about the QWidget.windowFlags property: http://doc.qt.nokia.com/4.7/qwidget.html#windowFlags-prop

Example:

>>> from PyQt4 import QtGui, QtCore
>>> app = QtGui.QApplication([])
>>> win = QtGui.QMainWindow()
>>> win.setWindowFlags(win.windowFlags() | QtCore.Qt.FramelessWindowHint)
>>> win.show()
Boy answered 6/5, 2011 at 15:42 Comment(3)
Thanks for this. I haven't found any flag to reserve space on the screen in the Qt4 documentation. Google doesn't provide any hint either. (Perhaps i am not formulating it well?)Concertgoer
I haven't seen anything about reserved space or workspaces in Qt.. you might need to get direct access to your window manager for that.Boy
That's what i feared, so i already reformulated the question for general purpose. Thanks anyway.Concertgoer
H
1
import sys
from PyQt4 import QtGui, QtCore


class Example(QtGui.QWidget):

    def __init__(self):
        super(Example, self).__init__()

        self.initUI()

    def initUI(self):               

        qbtn = QtGui.QPushButton('Quit', self)
        #qbtn.clicked.connect(QtCore.QCoreApplication.instance().quit)
        qbtn.clicked.connect(self.test)
        qbtn.resize(qbtn.sizeHint())
        qbtn.move(50, 50)       

        self.setGeometry(300, 300, 250, 150)
        self.setWindowTitle('Quit button')    
        self.setWindowFlags(self.windowFlags() | QtCore.Qt.FramelessWindowHint)
        self.show()

    def test(self):
      print "test"

def main():

    app = QtGui.QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())


if __name__ == '__main__':
    main()
Hello answered 7/11, 2013 at 0:7 Comment(0)
C
0

The solution is to use Python-Xlib, and it has been described in an answer on a universal way to reserve screen space on X.

Concertgoer answered 3/6, 2011 at 20:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.