java的textarea分页,Qt5/QML-在文本/文本区域中分页

你可以测量

TextArea

装载后的高度,除以容器高度,得到页数。然后你只要移动

根据当前页相对于其容器。

import QtQuick 2.12

import QtQuick.Window 2.12

import QtQuick.Controls 2.5

import QtQuick.Layouts 1.3

Window {

id: main

visible: true

width: 640

height: 800

property int currentPage: 1

property int pageCount: 1

ColumnLayout

{

anchors.fill: parent

anchors.margins: 5

RowLayout {

Layout.preferredHeight: 40

Layout.alignment: Qt.AlignHCenter

Button {

text: "

onClicked: {

if(main.currentPage > 1)

main.currentPage --;

}

}

Text {

text: main.currentPage + " / " + main.pageCount

}

Button {

text: ">"

onClicked: {

if(main.currentPage < main.pageCount)

main.currentPage ++;

}

}

}

Rectangle {

id: container

clip: true

Layout.fillHeight: true

Layout.fillWidth: true

TextArea {

id: msg

text: "Loading ..."

width: container.width

height: container.height

y: -(main.currentPage - 1) * container.height

textFormat: TextEdit.RichText

wrapMode: TextEdit.Wrap

Component.onCompleted: {

msg.makeRequest();

}

onContentHeightChanged: {

msg.height = msg.contentHeight;

if(msg.contentHeight >= container.height && container.height > 0)

{

main.pageCount = msg.contentHeight / container.height;

loader.running = false;

}

}

function makeRequest()

{

var doc = new XMLHttpRequest();

msg.text = "";

doc.onreadystatechange = function() {

if (doc.readyState === XMLHttpRequest.DONE) {

msg.text = doc.responseText;

}

}

doc.open("GET", "http://www.gutenberg.org/files/730/730-h/730-h.htm");

doc.send();

}

}

}

}

BusyIndicator {

id: loader

running: true

anchors.centerIn: parent

}

}

当然,您必须处理页边距、页面的最后一行、重新计算调整大小时的值等。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值