Although it is relatively simple to use, it is necessary to go over it in person. You can take a study note and record it here.
# Include "tablewidgetxxx. H "# include <qtgui/qapplication> # include <qtgui/qtablewidget> typedef struct {char * country; double GDP, population;} gdp_facts; gdp_facts [] = {"United States", 14.6, 2.7 },{ "PRC China", 6.1, 13.0 },{ "Japan", 5.4, 1.3 }, {"Germany", 3.3, 0.8 },{ "United Kingdom", 2.3, 0.6 }}; int main (INT argc, char * argv []) {qapplication app (argc, argv); const int rows = 5, Colum NS = 4; // instantiate the table and specify the number of rows and columns qtablewidget widget (rows, columns); // set the table header qstringlist; list <"country" <"Grand GDP" <"Population" <"GDP per person"; widget. sethorizontalheaderlabels (list); For (int row = 0; row <rows; row ++) {// each items [J] represents a cell, make up a row of qtablewidgetitem * items [columns]; // set the cell style of each row for (Int J = 0; j <columns; j ++) {items [J] = new qtablewidgetitem (); // create a qtablewidget The item object indicates a cell data item in the table items [J]-> settextalignment (QT: alignhcenter); qfont font; font. setpointsize (16); items [J]-> setfont (font);} // set the cell content of each row gdp_facts * P = & gdp_facts [row]; // assign a struct pointer to point to the predefined fixed content items [0]-> setdata (QT: displayrole, p-> country ); // The constructed qvariant object stores a qstring value items [1]-> setdata (QT: displayrole, p-> GDP ); // The constructed qvariant object stores values of the double type items [2]-> setdata (QT: displayrole, p-> Po Pulation); items [3]-> setdata (QT: displayrole, p-> GDP/p-> population ); // set for (Int J = 0; j <columns; j ++) widgets one by one for cells in the table. setitem (row, J, items [J]); // call setitem () to add them to the internal model of qtablewidget.} // Set the table header sorting widget. setsortingenabled (true); widget. Resize (800,300); widget. Show (); Return app.exe C ();}
Refer:
Http://book.51cto.com/art/201207/347904.htm
Ultra-Detailed Description: tablewidget instructions and additions, deletions, and modifications
Http://www.cnblogs.com/li-peng/p/3654634.html
Qtablewidget is easy to use because there is no parent node relationship