Qt6 QML Book/画布/方便的API

Convenience API

方便的API

For operations on rectangles, a convenience API is provided which draws directly and does need a stroke or fill call.

对于矩形上的操作,提供了一个方便的API,它直接绘制,并且需要调用stroke或fill。

import QtQuick

Canvas {
    id: root
    width: 120; height: 120
    onPaint: {
        var ctx = getContext("2d")
        ctx.fillStyle = 'green'
        ctx.strokeStyle = "blue"
        ctx.lineWidth = 4

        // draw a filles rectangle
        ctx.fillRect(20, 20, 80, 80)
        // cut our an inner rectangle
        ctx.clearRect(30,30, 60, 60)
        // stroke a border from top-left to
        // inner center of the larger rectangle
        ctx.strokeRect(20,20, 40, 40)
    }
}

image

TIP

The stroke area extends half of the line width on both sides of the path. A 4 px lineWidth will draw 2 px outside the path and 2 px inside.

笔划区域延伸到路径两侧线宽的一半。4px线宽将在路径外部绘制2px,在路径内部绘制2px。

示例源码下载

本文档是QT中文版本 内容详尽,下面是片段 信号 void activated ( int id ) 静态公有成员 QKeySequence shortcutKey ( const QString & str ) QString keyToString ( QKeySequence k ) (obsolete) QKeySequence stringToKey ( const QString & s ) (obsolete) 保护成员 virtual bool eventFilter ( QObject * o, QEvent * e ) -------------------------------------------------------------------------------- 详细描述 QAccel类用来处理键盘的加速键和快捷键。 键盘加速键是在某个组合键按下的时候出发一个动作,加速键可以处理窗口部件和它子部件里所有的键盘动作所以它不会被键盘焦点所影响。 在大多数情况下,你不需要直接使用这个类。使用QAction类建立的具有加速键的动作可以同时在菜单和工具栏里使用。如果你的兴趣只是在菜单里使用QMenuData::insertItem()或者QMenuData::setAccel()建立只作用在菜单里的加速键。那么许多窗口部件可以自动的生成加速键,比如QButton、QGroupBox、QLabel(使用QLabel::setBuddy())、QMenuBar和QTabBar。实例: QPushButton p( "&Exit", parent ); // 自动使用快捷键ALT+Key_E QPopupMenu *fileMenu = new fileMenu( parent ); fileMenu->insertItem( "Undo", parent, SLOT(undo()), CTRL+Key_Z ); QAccel包括一个加速键的列表,这个列表里的项目可以使用insertItem()、removeItem()、clear()、key()和findKey()。 每一个加速键项目是由一个标示符和 QKeySequence组成。一个单独的键组是由一个键盘码组合上改变符形成的(SHIFT,CTRL,ALT 或者 UNICODE_ACCEL)。例如,CTRL + Key_p可以作为文本打印的快捷键。这个键的键盘码在qnamespace.h里列出。还有,使用UNICODE_ACCEL可以使字符以统一码(unicode)的形式表现出来。例如 UNICODE_ACCEL + 'A' 所给出的加速键和Key_A是一样的。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值