Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
201 views
in Technique[技术] by (71.8m points)

python - PyQt4: how to make undercorated window with reserved space

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 :)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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()

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...