pyqt4 borderless window
2017-02-10 00:42
316 查看
coding:utf-8
import sysfrom 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_())
相关文章推荐
- mac下borderless的window(无标题栏)如何实现
- Borderless button
- Android 实现borderless的Button并设置分界线
- window隐藏后tabpanel布局里的border布局显示不正常(已解决)defaults:{hideMode:'offsets'}
- Buttons in button bars should be borderless; use style="?android:attr/buttonBarButtonStyle" (and ?an
- Buttons in button bars should be borderless
- ExtJs学习笔记(9)_Window窗口的Border布局
- 解决编译出现TextAppearance.Material.Widget.Button.Borderless.Colored not found的问题
- Android中Button控件警告信息Buttons in button bars should be borderless
- Buttons in button bars should be borderless; use style="?android:attr/buttonBarButtonStyle" (and ?an
- pyqt4 close window by customed function
- selectableItemBackgroundBorderless 无效的问题
- Android L 设置background为?android:attr/selectableItemBackgroundBorderless问题小结
- ?selectableItemBackgroundBorderless遇到的问题
- easyui中window和message样式重写less
- ExtJs学习笔记(10)_Window窗口的Border布局
- 使用Ext.Window时出现No center region defined in BorderLayout错误的愿原因
- Android中Button控件Buttons in button bars should be borderless;警告信息
- Buttons in button bars should be borderless
- Java Swing Border(Swing 边框) 归纳