QT5: QT Quick和Qml和Qss

一.简介

 

Qt Quick

Qt提供的Qml的标准库,提供了大量的控件与C++混合编程,需要什么控件直接import进去

Qml

Qt元对象语言,类似json的声明语法,支持JavaScript语句

 

 

 

Qt样式表类似于HTML的层叠样式表(CSS),它是一个单独的.qss文件而不用去继承QStyle类

QSS是一种用来自定义控件外观的机制

 

 

二.Qml语法

import导入语句

import QtQuick 2.12
import QtQuick.Window 2.12
import"./myButton" as MyButton
import QtQuick.Contols 1.4 as Control
对象id和表达式

property: value
注释 属性 锚点(锚布局器) 基础控件与鼠标事件入门

 

 

 

三.Qt Quick基础

Window {
  
  Visible: true
  width: 640
  height: 480
  title:qsTr("Hello World")
  
  Control.Button {
    width: 100
    height: 30
    anchors.centerIn: parent
    text: "按钮"
  }    

  MyButton.Button {
    id: button
    width: 100
    height: 30
    color: "red"
  }

  ToolBar {
    width: 100
    height: 30
    anchors.top: button_1.top
    anchors.left: button_1.right
    color: "blue"
  }
    

}

 

 

 

四.Qt Quick控件

 

 

 

二.加载QSS文件

 

MainWidget::MainWidget(QWidget* parent) : 
    QWidget(parent), ui(new Ui::MainWidget)
{
  QFile file(":/qss/main.qss");
  file.open(QFile::ReadOnly);
  QTextStream filetext(&file);
  QString stylesheet = filetext.readAll();
  this->setStyleSheet(stylesheet);
  file.close();    
}    

 

三.QSS语法规则

 

QSS的语法规则和CSS语法规则类似,但是QSS的功能比CSS要弱很多,它的选择器和属性要少很多


一条QSS的样式包含了两个部分:

(1) 是选择器指定了哪些控件会受到影响

(2) 是指定了属性的值


QPushButton {color : red}

MyButton {color : red}

 

1.选择器

 

1.通配选择器

2.类型选择器

3.属性选择器

4.类选择器

5.ID选择器

6.后代选择器

7.子选择器

8.子控件选择器

9.伪状态选择器

 

posted @ 2021-10-15 17:39  言午丶  阅读(1981)  评论(0编辑  收藏  举报