fyne table之自定义cell width

以下代码转载自:https://gist.github.com/ledongthuc/9686787fe51bbe763fa1e50389d63351

package main

import (
	"fmt"

	"fyne.io/fyne"
	"fyne.io/fyne/app"
	"fyne.io/fyne/dialog"
	"fyne.io/fyne/widget"
)

func main() {
	a := app.New()
	w := a.NewWindow("Table Dialog")
	data := [][]string{
		{"a", "b", "c", "d", "e", "f"},
		{"g", "h", "i", "j", "k", "l"},
		{"m", "n", "o", "p", "q", "r"},
		{"s", "t", "u", "v", "w", "x"},
	}
	w.SetContent(widget.NewButton("Show Table Dialog", func() {
		l := widget.NewTable(
			func() (int, int) {
				return len(data), len(data[0])
			},
			func() fyne.CanvasObject {
				item := widget.NewLabel("Template")
				item.Resize(fyne.Size{
					Width:  200,
					Height: 20,
				})
				return item
			},
			func(cell widget.TableCellID, item fyne.CanvasObject) {
				item.(*widget.Label).SetText(fmt.Sprintf("Cell %s ABC XYZ MDN", data[cell.Row][cell.Col]))
				item.(*widget.Label).Resize(fyne.Size{
					Width:  200,
					Height: 20,
				})
			})
		d := dialog.NewCustom("Table Dialog", "OK", l, w)
		d.Show()
		d.Resize(fyne.NewSize(700, 500))
	}))
	w.Resize(fyne.NewSize(600, 600))
	w.ShowAndRun()
}

  

上一篇:Qt+MPlayer音乐播放器开发笔记(一):ubuntu上编译MPlayer以及Demo演示


下一篇:关于Qt选择qml还是widget的深度思考