资讯详情

Qt学习 第2节:QLabel

#include <QApplication>#include <QLabel.h>int main(int argc,char *argv{     QApplication app(argc,argv);    QLabel* mylabel= new QLabel("<h1><i>Hello</i><font color=red>Qt!</font></h1>");    mylabel->show();     return app.exec();}

工程构成

#ifndef WINDOW_H#define WINDOW_H#include <QMainWindow>#include <QLabel>   // 引入 QLable 标签组件头文件class Window : public QMainWindow{    / QMainWindow 是主窗,主窗有主菜单栏、工具栏和状态栏,类似于一般应用的主窗;   / QWidget 是所有具有可视界面类的基类,选择 QWidget 创建的界面可以支持各种界面组件;   / QDialog 是对话框类,可以建立基于对话框的界面;   Q_OBJECT     / 已定义为宏,所有需要信号和槽功能的组件必须是 Q_OBJECT 作为 private 属性成员被引入类中public:    Window(QWidget *parent = 0);    ~Window();private:    QLabel* label;  / 定义私有 QLabel 指针对象};#endif // WINDOW_H
#include "Window.h"Window::Window(QWidget *parent) : QMainWindow(parent){    this->label = new QLabel("Hello Qt !",this);//this指定当前空间的父窗Window    // 	QLabel的构造函数QLabel(const QString & text,QWidget * parent = 0,Qt::WindowFlags f = 0)}Window::~Window(){}

主函数main

#include "Window.h"#include <QApplication>// main  函数中分别定义了 QApplication 和 Window 对象需要引入 QApplication 和 Windows.h 头文件。int main(int argc,char *argv{     QApplication app(argc,argv);        Window w;    w.show();   / Qt 提供的所有组件(控件和部件)都是隐藏的,不会自动显示。通过调用 Window 类提供的 show() 方法,w 窗口就可以在程序运行后显示出来。   return app.exec();}

0.QLabel<--QFrame<--QWidget<--QObject and QPaintDevice

QLabel: provides a text or image display QFrame: the base class of widgets that can have a frame QWidget: the base class of all user interface objects QObject: the base class of all Qt objects QPaintDevice: the base class of objects that can be painted on with QPainter

0.QPushButton<--QAbstractButton<--QWidget<--QObject and QPaintDevice

QPushButton: provides a command button QAbstractButton: the abstract base class of button widgets,providing functionality common to buttons QWidget: the base class of all user interface objects QObject: the base class of all Qt objects QPaintDevice: the base class of objects that can be painted on with QPainter

1.QMainWindow<--QWidget<--QObject and QPaintDevice

QMainWindow: provides a main application window QWidget: the base class of all user interface objects QObject: the base class of all Qt objects QPaintDevice: the base class of objects that can be painted on with QPainter

1.QDialog<--QWidget<--QObject and QPaintDevice

QDialog: the base class of dialog windows QWidget: the base class of all user interface objects QObject: the base class of all Qt objects QPaintDevice: the base class of objects that can be painted on with QPainter

2.QApplication<--QGuiApplication<--QCoreApplication<--QObject

QApplication: manages the GUI application's control flow and main settings QGuiApplication: manages the GUI application's control flow and main settings QCoreApplication: provides an event loop for Qt applications without UI QObject: the base class of all Qt objects

3.QLayout<--QObject and QLayoutItem

QLayout: the base class of geometry managers QObject: the base class of all Qt objects QLayoutItem: provides an abstract item that a QLayout manipulates

标签: 涤纶myla电容

锐单商城拥有海量元器件数据手册IC替代型号,打造 电子元器件IC百科大全!

 锐单商城 - 一站式电子元器件采购平台  

 深圳锐单电子有限公司