Contents
  1. 1. PyQt窗口风格使用setWindowFlags(Qt.WindowFlags)函数设置,具体参数如下:
    1. 1.1. 工具/原料
    2. 1.2. 方法/步骤
PyQt窗口风格使用setWindowFlags(Qt.WindowFlags)函数设置,具体参数如下:
工具/原料

Python
PyQt

方法/步骤
  1. PyQt基本窗口类型有如下类型:

    Qt.Qt.Widget#插件默认窗口,有最小化、最大化、关闭按钮
    Qt.Qt.Window#普通窗口,有最小化、最大化、关闭按钮
    Qt.Qt.Dialog#对话框窗口,有问号和关闭按钮
    Qt.Qt.Popup#弹出窗口,窗口无边框化
    Qt.Qt.ToolTip#提示窗口,窗口无边框化,无任务栏窗口
    Qt.Qt.SplashScreen#飞溅屏幕,窗口无边框化,无任务栏窗口
    Qt.Qt.SubWindow#子窗口,窗口无按钮但有标题栏

  2. 自定义外观的顶层窗口标志:

    Qt.Qt.MSWindowsFixedSizeDialogHint#窗口无法调整大小
    Qt.Qt.FramelessWindowHint#窗口无边框化
    Qt.Qt.CustomizeWindowHint#有边框但无标题栏和按钮,不能移动和拖动
    Qt.Qt.WindowTitleHint#添加标题栏和一个关闭按钮
    Qt.Qt.WindowSystemMenuHint#添加系统目录和一个关闭按钮
    Qt.Qt.WindowMaximizeButtonHint#激活最大化和关闭按钮,禁止最小化按钮
    Qt.Qt.WindowMinimizeButtonHint#激活最小化和关闭按钮,禁止最大化按钮
    Qt.Qt.WindowMinMaxButtonsHint#激活最小化、最大化和关闭按钮,#相当于Qt.Qt.WindowMaximizeButtonHint|Qt.Qt.WindowMinimizeButtonHint
    Qt.Qt.WindowCloseButtonHint#添加一个关闭按钮
    Qt.Qt.WindowContextHelpButtonHint#添加问号和关闭按钮,像对话框一样
    Qt.Qt.WindowStaysOnTopHint#窗口始终处于顶层位置
    Qt.Qt.WindowStaysOnBottomHint#窗口始终处于底层位置

  3. 使用方法:
    在窗口类__init__函数中使用self.setWindowFlags()函数,如:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# -*- coding: utf-8 -*-
from PyQt4 import QtCore, QtGui, Qtfrom UI import *
class MainWindow(QtGui.QMainWindow):
def __init__(self,parent=None):
QtGui.QWidget.__init__(self,parent)
self.ui=Ui_Form() # Ui_Form来源于UI.py,参见系列第一课
self.ui.setupUi(self)
# 设置普通窗口样式
self.setWindowFlags(Qt.Qt.Window)
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
myapp=MainWindow()
myapp.show()
app.exec_()
Contents
  1. 1. PyQt窗口风格使用setWindowFlags(Qt.WindowFlags)函数设置,具体参数如下:
    1. 1.1. 工具/原料
    2. 1.2. 方法/步骤