QML ScrollView默认滚动条的使用
问题:
有的时候某一窗口限制在一定的大小导致内容显示不全并且不会自动出现滚动条,查了资料发现了Scrollview方法,将GroupBox放入Scrollview中,clip属性删除Scrollview以外的部分,完成。
全部代码:
import QtQuick 2.15
import QtQuick.Window 2.15
import QtQuick.Controls 2.14
import QtQuick.Layouts 1.2
Window {
width: 300
height: 200
visible: true
title: qsTr("NameList")
ScrollView{
width:300
height:200
clip:true
GroupBox{
GridLayout{
id:idlist
columns: 4
rows: 4
Text {
text:"姓名"
}
TextField{
id:name1
text:nametext1
onEditingFinished: {
nametext1 = text
}
}
Text {
text:"班级"
}
TextField{
id:class1
text:classtext1
onEditingFinished: {
classtext1 = text
}
}
Text {
text:"出生年月"
}
TextField{
id:birth1
text:birthtext1
onEditingFinished: {
birthtext1 = text
}
}
Text {
text:"身高"
}
TextField{
id:stature1
text:staturetext1
onEditingFinished: {
staturetext1 = text
}
}
Text {
text:"体重"
}
TextField{
id:weight1
text:weighttext1
onEditingFinished: {
weighttext1 = text
}
}
Text {
text:"语文"
}
TextField{
id:chinese1
text:chinesetext1
onEditingFinished: {
chinesetext1 = text
}
}
Text {
text:"数学"
}
TextField{
id:math1
text:mathtext1
onEditingFinished: {
mathtext1 = text
}
}
Text {
text:"英语"
}
TextField{
id:english1
text:englishtext1
onEditingFinished: {
englishtext1 = text
}
}
Text {
text:"物理"
}
TextField{
id:physical1
text:physicaltext1
onEditingFinished: {
physicaltext1 = text
}
}
}
}
}
}