小部件是可以在屏幕上显示的GUI元素。这可能包括标签、按钮、列表视图、窗口、对话框等。所有小部件都在屏幕上向用户显示特定信息,其中大多数小部件允许用户通过键盘或鼠标进行交互。
窗口是没有其他父窗口小部件的顶级窗口小部件。通常,除非指定了任何窗口标志,否则窗口都有标题栏和边框。窗口样式和某些策略由底层窗口系统决定。Qt中的一些常见窗口类是QMainWindow、QMessageBox和QDialog。主窗口通常遵循桌面应用程序的预定义布局,包括菜单栏、工具栏、中心小部件区域和状态栏。QMainWindow需要一个中心小部件,即使它只是一个占位符。其他组件可以在主窗口中移除。下图显示了QMainWindow的布局结构。我们通常调用show()方法来显示小部件或主窗口。
QMenuBar位于QMainWindow的顶部。你可以添加菜单选项,如文件、编辑、查看和帮助。在下面显示QMenuBar的屏幕截图中,有QToolBar。QDockWidget提供了一个小部件,可以停靠在QMainWindow内部,也可以作为顶级窗口浮动。中心窗口小部件是主视图区域,你可以在其中添加表单或子窗口小部件。使用子窗口小部件创建自己的视图区域,然后调用setCentralWidget()。

重要提示:
QMainWindow不应与QWindow混淆。QWindow是一个方便的类,表示底层窗口系统中的窗口。通常,应用程序的UI使用QWidget或QMainWindow。但是,如果希望保持最小的依赖关系,可以直接渲染到QWindow。
对话框是用于提供通知或接收用户输入的临时窗口,通常有“确定”和“取消”按钮。QMessageBox是一种对话框,用于显示信息和警报,或向用户提问。通常,exec()方法用于显示对话框。该对话框显示为模式对话框,在用户关闭它之前本质上是阻塞的。可以使用以下代码段创建一个简单的消息框:
QMessageBox messageBox;
messageBox.setText("This is a simple QMessageBox.");
messageBox.exec();
值得注意的是,所有这些都是小部件。窗口是顶级小部件,对话框是一种特殊的窗口。
本章介绍了Qt Widgets模块的基本原理以及如何创建自定义UI。在这里,你学习了使用Qt Designer设计和构建GUI。传统的桌面应用程序通常是用Qt设计器构建的。自定义小部件插件等功能允许你使用Qt Designer创建和使用自己的小部件集合。我们还讨论了使用样式表和样式定制应用程序的外观,以及小部件、窗口和对话框之间的用法和差异。现在,你可以创建一个带有扩展功能的自定义小部件的GUI应用程序,并为桌面应用程序创建自己的主题。
A complete guide to designing and building fun games with Qt and Qt Quick 2 using associated toolsets
About This Book
Learn to create simple 2D to complex 3D graphics and games using all possible tools and widgets available for game development in Qt
Understand technologies such as QML, Qt Quick, OpenGL, and Qt Creator, and learn the best practices to use them to design games
Learn Qt with the help of many sample games introduced step-by-step in each chapter
Who This Book Is For
If you want to create great graphical user interfaces and astonishing games with Qt, this book is ideal for you. Any previous knowledge of Qt is not required, however knowledge of C++ is mandatory.
What You Will Learn
Install Qt on your system
Understand the basic concepts of every Qt game and application
Develop 2D object-oriented graphics using Qt Graphics View
Build multiplayer games or add a chat function to your games with Qt's Network module
Script your game with Qt Script
Program resolution-independent and fluid UI using QML and Qt Quick
Control your game flow as per the sensors of a mobile device
See how to test and debug your game easily with Qt Creator and Qt Test
In Detail
Qt is the leading cross-platform toolkit for all significant desktop, mobile, and embedded platforms and is becoming more popular by the day, especially on mobile and embedded devices. Despite its simplicity, it's a powerful tool that perfectly fits game developers' needs. Using Qt and Qt Quick, it is easy to build fun games or shiny user interfaces. You only need to create your game once and deploy it on all major platforms like iOS, Android, and WinRT without changing a single source file.
The book begins with a brief introduction to creating an application and preparing a working environment for both desktop and mobile platforms. It then dives deeper into the basics of creating graphical interfaces and Qt core concepts of data processing and display before you try creating a game. As you progress through t
前些天跟同学交流,谈到了 PyQt5,说是曾经看过这东西,觉得难学麻烦。我也是最近用到才学的,总共耗时三天,前两天时间看官方文档,第三天发现了 Designer 这东西,内心呐喊,这还写个锤子代码!!
本文偏向于应用型,对于一些概念性的东西没有太多的深究。从基本介绍到多窗口的应用,演示了一些常用的功能,基本上学完这些就可以了。想看生成代码部分的可以直接跳到最后。
目录写在前面一、QT Designer1.1 介绍与安装1.2 基本使用二、布局与预设2.1 四大布局2.2 sizePolicy三、
The Insider's Best-Practice Guide to Rapid PyQt GUI Development
Whether you're building GUI prototypes or full-fledged cross-platform GUI applications with native look-and-feel, PyQt is your fastest, easiest, most powerful solution. Qt expert Mark Summerfield has written the definitive best-practice guide to PyQt development.
Coverge includes
Python basics for every PyQt developer: data types, data structures, control structures, classes, modules, and more
Core PyQt GUI programming techniques: dialogs, main windows, and custom file formats
Using Qt Designer to design user interfaces, and to implement and test dialogs, events, the Clipboard, and drag-and-drop
Building custom widgets: Widget Style Sheets, composite widgets, subclassing, and more
Making the most of Qt 's new graphics/view architecture
Connecting to databases, executing SQL queries, and using form and table views
Advanced model/view programming: custom views, generic delegates, and more
Implementing online help, internationalizing applications, and using PyQt's networking and multithreading facilities
Editorial Reviews
Develop more dynamic and robust GUI applications using an open source cross-platform UI framework
Overview
Designed for beginners to help them get started with GUI application development
Develop your own applications by creating customized widgets and dialogs
Written in a simple and elegant structure to help you easily understand how to program various GUI components
In Detail
Elegantly built GUI applications are always a massive hit among users. PySide is an open source software project that provides Python bindings for the Qt cross-platform UI framework. Combining the power of Qt and Python, PySide provides easy access to the Qt framework for Python developers and also acts as an excellent rapid application development platform available on all major operating systems.
This book aims to help you develop GUI applications easily using PySide. Python is easy to learn and use and its programs are relatively shorter than those written in other programming languages like C++ or Java. This book will introduce you to user interface programming in Python, allowing you to develop real-time applications in a shorter amount of time.
This book will take you through everything you need to know to develop UI applications. You will learn about installing/building PySide in various major operating systems as well as the basics of GUI programming. The book will then move on to discuss event management, signals and slots, and the widgets and dialogs available with PySide. Database interaction and manipulation is also covered.
In a nutshell, this book is great for learning how to program applications with GUI and for mastering how to develop your own applications and how to run them across platforms.
What you will learn from this book
Download and install/build PySide, a cross-platform GUI development toolkit for Python
Program GUI applications in an easy and efficient way
Create and work with windowed applications
Create menus, toolbars, status bars, and child windows
Connect your GUI to a database and manage it
Approach
An accessible and practical guide to developing GUI’s for Python applications.
Who this book is written for
This book is written for Python programmers who want to learn about GUI programming. It is also suitable for those who are new to Python but are familiar with object-oriented programming.
Table of Contents
Chapter 1: Getting Started with PySide
Chapter 2: Entering through Windows
Chapter 3: Main Windows and Layout Management
Chapter 4: Events and Signals
Chapter 5: Dialogs and Widgets
Chapter 6: Handling Databases
Book Details
Title: PySide GUI Application Development
Author: Venkateshwaran Loganathan
Length: 140 pages
Edition: 1
Language: English
Publisher: Packt Publishing
Publication Date: 2013-10-15
ISBN-10: 1849699593
ISBN-13: 9781849699594
Develop more dynamic and robust GUI applications using PySide, an open source cross-platform UI framework
About This Book
Designed for beginners to help you get started with GUI application development
Develop your own applications by creating customized widgets and dialogs
Written in a simple and elegant structure so you easily understand how to program various GUI components
Who This Book Is For
This book is written for Python programmers who want to learn about GUI programming. It is also suitable for those who are new to Python but are familiar with object-oriented programming.
What You Will Learn
Program GUI applications in an easy and efficient way
Download and install PySide, a cross-platform GUI development toolkit for Python
Create menus, toolbars, status bars, and child windows
Develop a text editor application on your own
Connect your GUI to a database and manage it
Execute SQL queries by handling databases
In Detail
Elegantly-built GUI applications are always a massive hit among users. PySide is an open source software project that provides Python bindings for the Qt cross-platform UI framework. Combining the power of Qt and Python, PySide provides easy access to the Qt framework for Python developers and also acts as an excellent rapid application development platform.
This book will take you through everything you need to know to develop UI applications. You will learn about installing and building PySide in various major operating systems as well as the basics of GUI programming. The book will then move on to discuss event management, signals and slots, and the widgets and dialogs available with PySide. Database interaction and manipulation is also covered.
By the end of this book, you will be able to program GUI applications efficiently and master how to develop your own applications and how to run them across platforms.
Style and approach
This is an accessible and practical guide to developing GUIs for Python applications.
Table of Contents
转自:http://hi.baidu.com/topone_top/item/4511e790f2beaa9a58146190
QStackedLayout类把子控件进行分组或者分页,一次只显示一组或者一页,隐藏其他组或者页上的控件。QStackedLayout本身并不可见,对换页也不提供本质的支持。图6.5中的建头和黑灰色的框架是Qt Designer提供为了方便设计。为了方便起见,Qt还提供
QStackedLayout类提供了一堆小部件,其中一次仅一个小部件可见。
QStackedLayout可用于创建类似于QTabWidget提供的用户界面。基于QStackedLayout还构建了一个便利的QStackedWidget类。
通过一个小例子来介绍基本使用方法,效果如下
QStackedLayout可以填充许多子窗口小部件(“页面”)。例如:
QWidge...
QLabel ------------------------------------------------------------------------
//#include"mainwindow.h"
#include<QApplication>
#include<QLabel>
intmain(intargc,char*argv[])
QApp...
版权声明:著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处
QObjectQCoreApplicationQGuiApplicationQApplication
QCoreApplication定义在core模块中,为应用程序提供了一个非gui的事件循环;
QGuiApplication定义在gui模块中,提供了额外的gui相关的设置,比如...
如果定义了QT_WIDGETS_LIB,那么应用程序的对象就是QApplication;
如果定义了QT_GUI_LIB,那么应用程序的对象就是QGuiApplication;
否则,应用程序的对象就是QCoreApplication。
如果使用qmake,并且配置中包含QT += widgets,那么就会自动定义QT_WIDGETS_LIB;
类似的,如果使用了qmake,并且配置中包含QT ...