This commit is contained in:
朱子楚\zhuzi
2024-05-04 23:56:20 +08:00
parent 18685b17ec
commit af270951da
5 changed files with 259 additions and 44 deletions

View File

@ -3,30 +3,76 @@ import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15
import FluentUI 1.0
ColumnLayout {
default property alias buttons: control.data
property int currentIndex : -1
Item{
id:control
onCurrentIndexChanged: {
for(var i = 0;i<buttons.length;i++){
buttons[i].checked = false
}
var button = buttons[currentIndex]
if(button){
button.checked = true
default property list<QtObject> buttons
property int currentIndex : -1
property int spacing: 8
property int orientation: Qt.Vertical
QtObject{
id: d
function updateChecked(){
if(buttons.length === 0){
return
}
for(var i = 0;i<buttons.length;i++){
buttons[i].checked = false
}
buttons[currentIndex].checked = true
}
}
Component.onCompleted: {
for(var i = 0;i<buttons.length;i++){
buttons[i].clickListener = function(){
for(var i = 0;i<buttons.length;i++){
var button = buttons[i]
if(this === button){
currentIndex = i
implicitWidth: childrenRect.width
implicitHeight: childrenRect.height
onCurrentIndexChanged: {
d.updateChecked()
}
Component{
id:com_vertical
ColumnLayout {
data: control.buttons
spacing: control.spacing
Component.onCompleted: {
for(var i = 0;i<control.buttons.length;i++){
control.buttons[i].clickListener = function(){
for(var i = 0;i<control.buttons.length;i++){
var button = control.buttons[i]
if(this === button){
control.currentIndex = i
}
}
}
}
if(control.currentIndex < 0){
control.currentIndex = 0
}
d.updateChecked()
}
}
currentIndex = 0
}
Component{
id:com_horizontal
RowLayout {
data: buttons
spacing: control.spacing
Component.onCompleted: {
for(var i = 0;i<control.buttons.length;i++){
control.buttons[i].clickListener = function(){
for(var i = 0;i<control.buttons.length;i++){
var button = control.buttons[i]
if(this === button){
control.currentIndex = i
}
}
}
}
if(control.currentIndex < 0){
control.currentIndex = 0
}
d.updateChecked()
}
}
}
FluLoader{
sourceComponent: control.orientation === Qt.Vertical ? com_vertical : com_horizontal
}
}

View File

@ -4,30 +4,76 @@ import QtQuick.Controls.Basic
import QtQuick.Layouts
import FluentUI
ColumnLayout {
default property alias buttons: control.data
property int currentIndex : -1
Item{
id:control
onCurrentIndexChanged: {
for(var i = 0;i<buttons.length;i++){
buttons[i].checked = false
}
var button = buttons[currentIndex]
if(button){
button.checked = true
default property list<QtObject> buttons
property int currentIndex : -1
property int spacing: 8
property int orientation: Qt.Vertical
QtObject{
id: d
function updateChecked(){
if(buttons.length === 0){
return
}
for(var i = 0;i<buttons.length;i++){
buttons[i].checked = false
}
buttons[currentIndex].checked = true
}
}
Component.onCompleted: {
for(var i = 0;i<buttons.length;i++){
buttons[i].clickListener = function(){
for(var i = 0;i<buttons.length;i++){
var button = buttons[i]
if(this === button){
currentIndex = i
implicitWidth: childrenRect.width
implicitHeight: childrenRect.height
onCurrentIndexChanged: {
d.updateChecked()
}
Component{
id:com_vertical
ColumnLayout {
data: control.buttons
spacing: control.spacing
Component.onCompleted: {
for(var i = 0;i<control.buttons.length;i++){
control.buttons[i].clickListener = function(){
for(var i = 0;i<control.buttons.length;i++){
var button = control.buttons[i]
if(this === button){
control.currentIndex = i
}
}
}
}
if(control.currentIndex < 0){
control.currentIndex = 0
}
d.updateChecked()
}
}
currentIndex = 0
}
Component{
id:com_horizontal
RowLayout {
data: buttons
spacing: control.spacing
Component.onCompleted: {
for(var i = 0;i<control.buttons.length;i++){
control.buttons[i].clickListener = function(){
for(var i = 0;i<control.buttons.length;i++){
var button = control.buttons[i]
if(this === button){
control.currentIndex = i
}
}
}
}
if(control.currentIndex < 0){
control.currentIndex = 0
}
d.updateChecked()
}
}
}
FluLoader{
sourceComponent: control.orientation === Qt.Vertical ? com_vertical : com_horizontal
}
}