QTableWidget is usually used for data display. Through its table layout, users can see the data more clearly and filter the data more intuitively.
However, beginners and careless people will always find that their data has been added normally, but after the program runs, they can not see any data on the QTableWidget, a blank.
What's going on? Let's look at a code that can reproduce this problem:
Code that causes data not to be displayed1 func main() { 2 widgets.NewQApplication(len(os.Args), os.Args) 3 4 table := widgets.NewQTableWidget(nil) 5 table.SetColumnCount(3) 6 table.SetHorizontalHeaderLabels([]string{"number", "Full name", "Age"}) 7 // Remove borders 8 table.SetShowGrid(false) 9 10 // Setting data 11 num1 := widgets.NewQTableWidgetItem2("0", 0) 12 name1 := widgets.NewQTableWidgetItem2("anmi", 0) 13 age1 := widgets.NewQTableWidgetItem2("20", 0) 14 table.SetItem(0, 0, num1) 15 table.SetItem(0, 1, name1) 16 table.SetItem(0, 2, age1) 17 18 num2 := widgets.NewQTableWidgetItem2("1", 0) 19 name2 := widgets.NewQTableWidgetItem2("terra", 0) 20 age2 := widgets.NewQTableWidgetItem2("24", 0) 21 table.SetItem(1, 0, num2) 22 table.SetItem(1, 1, name2) 23 table.SetItem(1, 2, age2) 24 25 table.SetWindowTitle("QTableWidget") 26 table.Show() 27 28 widgets.QApplication_Exec() 29 }