#!/usr/bin/python
# -*- coding: utf-8 -*- """
ZetCode PyQt4 tutorial In this example, we dispay an image
on the window. author: Jan Bodnar
website: zetcode.com
last edited: September 2011
""" import sys
from PyQt4 import QtGui, QtCore class Example(QtGui.QWidget): def __init__(self):
super(Example, self).__init__() self.initUI() def initUI(self): hbox = QtGui.QHBoxLayout(self)
# We create a QtGui.QPixmap object. It takes the name of the file as a parameter.
pixmap = QtGui.QPixmap("redrock.png") lbl = QtGui.QLabel(self)
# We put the pixmap into the QtGui.QLabel widget.
lbl.setPixmap(pixmap) hbox.addWidget(lbl)
self.setLayout(hbox) self.move(300, 200)
self.setWindowTitle('Red Rock')
self.show() def main(): app = QtGui.QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_()) if __name__ == '__main__':
main() -------------------------------------------------------------------------------- #!/usr/bin/python
# -*- coding: utf-8 -*- """
ZetCode PyQt4 tutorial This example shows text which
is entered in a QtGui.QLineEdit
in a QtGui.QLabel widget. author: Jan Bodnar
website: zetcode.com
last edited: August 2011
""" import sys
from PyQt4 import QtGui, QtCore class Example(QtGui.QWidget): def __init__(self):
super(Example, self).__init__() self.initUI() def initUI(self): self.lbl = QtGui.QLabel(self)
# The QtGui.QLineEdit widget is created.
qle = QtGui.QLineEdit(self) qle.move(60, 100)
self.lbl.move(60, 40) # If the text in the line edit widget changes, we call the onChanged() method.
qle.textChanged[str].connect(self.onChanged) self.setGeometry(300, 300, 280, 170)
self.setWindowTitle('QtGui.QLineEdit')
self.show() # Inside the onChanged() method, we set the typed text to the label widget. We call the adjustSize() method to adjust the size of the label to the length of the text.
def onChanged(self, text): self.lbl.setText(text)
self.lbl.adjustSize() def main(): app = QtGui.QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_()) if __name__ == '__main__':
main() -------------------------------------------------------------------------------- #!/usr/bin/python
# -*- coding: utf-8 -*- """
ZetCode PyQt4 tutorial This example shows
how to use QtGui.QSplitter widget. author: Jan Bodnar
website: zetcode.com
last edited: September 2011
""" import sys
from PyQt4 import QtGui, QtCore class Example(QtGui.QWidget): def __init__(self):
super(Example, self).__init__() self.initUI() def initUI(self): hbox = QtGui.QHBoxLayout(self) # We use a styled frame in order to see the boundaries between the QtGui.QFrame widgets.
topleft = QtGui.QFrame(self)
topleft.setFrameShape(QtGui.QFrame.StyledPanel) topright = QtGui.QFrame(self)
topright.setFrameShape(QtGui.QFrame.StyledPanel) bottom = QtGui.QFrame(self)
bottom.setFrameShape(QtGui.QFrame.StyledPanel) # We create a QtGui.QSplitter widget and add two frames into it.
splitter1 = QtGui.QSplitter(QtCore.Qt.Horizontal)
splitter1.addWidget(topleft)
splitter1.addWidget(topright) # We can also add a splitter to another splitter widget.
splitter2 = QtGui.QSplitter(QtCore.Qt.Vertical)
splitter2.addWidget(splitter1)
splitter2.addWidget(bottom) hbox.addWidget(splitter2)
self.setLayout(hbox)
QtGui.QApplication.setStyle(QtGui.QStyleFactory.create('Cleanlooks')) self.setGeometry(300, 300, 300, 200)
self.setWindowTitle('QtGui.QSplitter')
self.show() def main(): app = QtGui.QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_()) if __name__ == '__main__':
main() -------------------------------------------------------------------------------- #!/usr/bin/python
# -*- coding: utf-8 -*- """
ZetCode PyQt4 tutorial This example shows
how to use QtGui.QComboBox widget. author: Jan Bodnar
website: zetcode.com
last edited: September 2011
""" import sys
from PyQt4 import QtGui, QtCore class Example(QtGui.QWidget): def __init__(self):
super(Example, self).__init__() self.initUI() def initUI(self): self.lbl = QtGui.QLabel("Ubuntu", self) # We create a QtGui.QComboBox widget with five options.
combo = QtGui.QComboBox(self)
combo.addItem("Ubuntu")
combo.addItem("Mandriva")
combo.addItem("Fedora")
combo.addItem("Red Hat")
combo.addItem("Gentoo") combo.move(50, 50)
self.lbl.move(50, 150) # Upon an item selection, we call the onActivated() method.
combo.activated[str].connect(self.onActivated) self.setGeometry(300, 300, 300, 200)
self.setWindowTitle('QtGui.QComboBox')
self.show() # Inside the method, we set the text of the chosen item to the label widget. We adjust the size of the label.
def onActivated(self, text): self.lbl.setText(text)
self.lbl.adjustSize() def main(): app = QtGui.QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_()) if __name__ == '__main__':
main()

ZetCode PyQt4 tutorial widgets II的更多相关文章

  1. ZetCode PyQt4 tutorial widgets I

    #!/usr/bin/python # -*- coding: utf-8 -*- """ ZetCode PyQt4 tutorial In this example, ...

  2. ZetCode PyQt4 tutorial layout management

    !/usr/bin/python -*- coding: utf-8 -*- """ ZetCode PyQt4 tutorial This example shows ...

  3. ZetCode PyQt4 tutorial First programs

    #!/usr/bin/python # -*- coding: utf-8 -*- """ ZetCode PyQt4 tutorial In this example, ...

  4. ZetCode PyQt4 tutorial Drag and Drop

    #!/usr/bin/python # -*- coding: utf-8 -*- """ ZetCode PyQt4 tutorial This is a simple ...

  5. ZetCode PyQt4 tutorial Dialogs

    #!/usr/bin/python # -*- coding: utf-8 -*- """ ZetCode PyQt4 tutorial In this example, ...

  6. ZetCode PyQt4 tutorial signals and slots

    #!/usr/bin/python # -*- coding: utf-8 -*- """ ZetCode PyQt4 tutorial In this example, ...

  7. ZetCode PyQt4 tutorial work with menus, toolbars, a statusbar, and a main application window

    !/usr/bin/python -*- coding: utf-8 -*- """ ZetCode PyQt4 tutorial This program create ...

  8. ZetCode PyQt4 tutorial custom widget

    #!/usr/bin/python # -*- coding: utf-8 -*- """ ZetCode PyQt4 tutorial In this example, ...

  9. ZetCode PyQt4 tutorial basic painting

    #!/usr/bin/python # -*- coding: utf-8 -*- """ ZetCode PyQt4 tutorial In this example, ...

随机推荐

  1. soapUI-DataSource Loop

    1.1.1  DataSource Loop 当我们需要遍历某DataSource中的所有内容时.需要在TestCase中添加DataSource Loop步骤,然后双击它进行配置,如下图所示: Op ...

  2. #ifdef和#if defined的差别

    注意两者都有个define的作用,区别在于使用方式上.前者的通常用法是:#ifdef  XXX .... #else .... #endif 只能在两者中选择是否有定义.对于后者,常用法是: #if ...

  3. 使用U盘安装linux系统

    1. 下载并安装:UltraISO.流氓软件太多,最后是在百度软件中心下的,推荐. 2. 插入U盘.打开UltraISO,然后:文件 -- 打开 -- 选择你的ISO文件,打开. 3. UltraIS ...

  4. 使用docker创建aosp编译环境

    如果只需要编译一个版本的aosp,那么如果在主机上架建环境即可,可写的程序如果要在各个aosp版本中编译,那在主机上架建多个aosp编译环境可以会比较麻烦,github上找到一个openstf用doc ...

  5. poj1985 / poj2631(树的直径)

    poj1985 Cow Marathon 树的直径裸题 树的直径的一般求法: 任意一点为起点,dfs/bfs找出与它最远的点$u$ 以$u$为起点,dfs/bfs找出与它最远的点$v$ 则$d(u,v ...

  6. tensorflow 安装GPU版本,个人总结,步骤比较详细【转】

    本文转载自:https://blog.csdn.net/gangeqian2/article/details/79358543 手把手教你windows安装tensorflow的教程参考另一篇博文ht ...

  7. Elasticsearch之中文分词器插件es-ik(博主推荐)

    前提 什么是倒排索引? Elasticsearch之分词器的作用 Elasticsearch之分词器的工作流程 Elasticsearch之停用词 Elasticsearch之中文分词器 Elasti ...

  8. HDU 3435 A new Graph Game(最小费用流:有向环权值最小覆盖)

    http://acm.hdu.edu.cn/showproblem.php?pid=3435 题意:有n个点和m条边,你可以删去任意条边,使得所有点在一个哈密顿路径上,路径的权值得最小. 思路: 费用 ...

  9. error: device offline - waiting for device -

    解决方法:重启服务 一.关闭 adb kill-server 二.启动 adb start-server 三.连接 adb connect 192.168.1.10 四.查看设备 adb device ...

  10. vue2.0中v-on绑定自定义事件

    vue中父组件通过prop传递数据给子组件,而想要将子组件的数据传递给父组件,则可以通过自定义事件的绑定. 每个Vue实例都实现了[事件接口],即: 1.使用 $on(eventName) 监听事件 ...