zoukankan      html  css  js  c++  java
  • pyqt4 borderless window

    coding:utf-8

    import sys
    from PyQt4.QtGui import (QApplication, QWidget, QPushButton, QLineEdit, QHBoxLayout, QVBoxLayout, QColorDialog, QInputDialog, QFileDialog, QCursor, QColor)

    from PyQt4.QtCore import Qt

    class Example(QWidget):
    def init(self):
    super(Example, self).init()
    self.style = """
    QPushButton{background-color:grey;color:white;}
    #window{ background:pink; }
    #test{ background-color:black;color:white; }
    """
    self.setStyleSheet(self.style)
    self.setWindowFlags(Qt.FramelessWindowHint)
    self.initUI()

    def initUI(self):
        self.setGeometry(300, 300, 300, 220)
        self.setWindowTitle('test')
        self.setObjectName("window")
    
        btn1 = QPushButton(u"关闭", self)
        btn1.clicked.connect(self.close)
        btn1.setObjectName('test')
        btn2 = QPushButton(u"最小化", self)
        btn2.clicked.connect(self.showMinimized)
        btn3 = QPushButton(u"最大化", self)
        btn3.clicked.connect(self.showMaximized)
    
        btn11 = QPushButton(u"改变背景", self)
        btn11.clicked.connect(self.showColor)
        btn22 = QPushButton(u"选择文件", self)
        btn22.clicked.connect(self.showFile)
        btn33 = QPushButton(u"对话框", self)
        btn33.clicked.connect(self.showDialog)
        self.linet1 = QLineEdit("111111", self)
        self.linet2 = QLineEdit("ssssssss", self)
    
        hbox1 = QHBoxLayout()  # 水平布局
        hbox1.addWidget(btn1)
        hbox1.addWidget(btn2)
        hbox1.addWidget(btn3)
        hbox2 = QHBoxLayout()  # 水平布局
        hbox2.addWidget(btn11)
        hbox2.addWidget(btn22)
        hbox2.addWidget(btn33)
        vbox = QVBoxLayout()  # 垂直布局
        vbox.addLayout(hbox1)
        vbox.addLayout(hbox2)
        vbox.addWidget(self.linet1)
        vbox.addWidget(self.linet2)
        self.setLayout(vbox)
    
        self.show()
    
    def mousePressEvent(self, event):
        if event.button() == Qt.LeftButton:
            self.m_drag = True
            self.m_DragPosition = event.globalPos() - self.pos()
            event.accept()
            self.setCursor(QCursor(Qt.OpenHandCursor))
    
    def mouseMoveEvent(self, QMouseEvent):
        if Qt.LeftButton and self.m_drag:
            self.move(QMouseEvent.globalPos() - self.m_DragPosition)
            QMouseEvent.accept()
    
    def mouseReleaseEvent(self, QMouseEvent):
        self.m_drag = False
        self.setCursor(QCursor(Qt.ArrowCursor))
    
    def showColor(self):
        col = QColorDialog.getColor()
        if col.isValid():
            self.setStyleSheet(self.style + "#window{background:%s}" % col.name())
    
    def showDialog(self):
        text, ok = QInputDialog.getText(self, u'对话框',
                                        u'请输入你的名字:')
    
        if ok:
            self.linet1.setText(str(text))
    
    def showFile(self):
        fname = QFileDialog.getOpenFileName(self, 'Open file', '/home')
    
        if fname[0]:
            f = open(fname[0], 'r')
    
            with f:
                data = f.readline()
                self.linet1.setText(data)
    

    if name == 'main':
    app = QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())

  • 相关阅读:
    u-boot.lds分析
    u-boot的makefile中的一些目录的设定,以及涉及的shell,make语法。
    u-boot入门第一步,分析mkconfig
    uboot学习——Makefile里的echo使用!
    Linux下的打包与压缩和tar命令!
    关于undefined reference的问题
    JZ2440 编译Uboot1.1.6 undefined reference to ‘raise’
    POJ 1094 Sorting It All Out
    链式前向星
    Codeforces Round #197 (Div. 2) A~D
  • 原文地址:https://www.cnblogs.com/otfsenter/p/6384750.html
Copyright © 2011-2022 走看看