Button是很常见的控件,Qt助手的说明如下:
Button QML Type
Push-button that can be clicked to perform a command or answer a question. More...
Import Statement: import QtQuick.Controls 2.5
Since: Qt 5.7
Inherits: AbstractButton
Inherited By: RoundButton and ToolButton
根据以上可知,在QML中要使用Buttoon,需要先导入控件库 import QtQuick.Controls 2.5, 使用其它控件也是一样,都需要导入这个库。
在界面上添加一个按钮
import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 2.5
Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
Button{
x:100 //设置按钮的横坐标
y:100 //设置纵坐标