Qtablewidget is easy to use because there is no parent node relationship

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.