Summary of Qtreewidget and Qtreewidgetitem usage

Source: Internet
Author: User

Qtreewidgetitem::addchild (qtreewidgetitem*)//For adding child nodes to the root node

Qtreewidget::setcolumncount; The number of columns used to set the columns in the table, with the corresponding display in the header.

Qtreewidget::setheaderhidden (); Hide table Header

Qtreewidgetitem::setsortingenabled (BOOL)//Can be used to set whether it can be sorted, when True, click on the table header, will automatically sort

Openpersistenteditor and Closepersistenteditor//used to control whether an item can be edited

Qtreewidgetitem * Qtreewidget::currentitem ()//const returns the current item pointer,

int Qtreewidget::currentcolumn ()//const put back the column number of the current item

Qtreewidgetitem * Qtreewidget::itemat (int x, int y) const Returns the item pointer at the given position

Qtreewidgetitem * Qtreewidget::itembelow (const QTREEWIDGETITEM * Item) const//Returns the item specified below item

Qtreewidgetitem * Qtreewidget::itemabove (const QTREEWIDGETITEM * Item) const//Returns the specified item above item

When looking for item, Qlistwidget and Qtablewidget have multiple find matching patterns.

Qlist<qtreewidgetitem *> qtreewidget::finditems (const QString & text, qt::matchflags flags, int column = 0) c Onst

Show hidden columns:

Setsectionhidden (int, bool); Issectionhidden (int);

Add delete top layer by:

Addtoplevelitem (qtreewidgetitem*);

Taketopleveltem (int);

Toplevelitem (int); Return

Toplevelitemcount ();

To add a delete sub-layer:

AddChild (qtreewidgetitem*);

Addchildren (const qlist<qtreewidgetitem*>&);

Takechild (int);

Takechildren ();

Child (int)//return

ChildCount ();

Sort

Treewidget->setsortingenabled (TRUE);

Treewidget->header ()->setsortindicatorshown (true);

Treewidget->header ()->setsortindicator (0, Qt::ascendingorder);

To customize, use the signal.

Connect (Treewidget->header (), SIGNAL (sectionclicked (int)), this, SLOT (sectionclickedslot (int)));

Two ways to add a table header

Method One:

Qstringlist header;

header<< "Ecjtu" << "CERT";

Treewidget->setheaderlabels (header); Set up the table header

Method Two:

Qstringlist header;

header<< "Ecjtu" << "CERT";

Qtreewidgetitem *head=new Qtreewidgetitem ((qtreewidget*) 0,header);

Treewidget->setheaderitem (head);

Initialized with basic use:

This->setmousetracking (TRUE);

This->setrootisdecorated (FALSE);

This->setselectionmode (qabstractitemview::extendedselection);

This->setstylesheet ("qtreewidget::item{height:25px}"); Set the line width and I can't find the interface provided setstylesheet very powerful suggestions to see

This->setcolumnwidth (0, 100); Set column widths

This->setcolumncount (2);

Qstringlist lists;

Lists << "NO" << "name";

This->setheaderlabels (lists);

for (int i=0;i<10;i++)

{

Qstringlist ContentList;

ContentList << QString ("00%1"). Arg (i) << "boy";

Qtreewidgetitem *pnewitem = new Qtreewidgetitem (this, contentlist); Increase

Pnewitem->setbackgroundcolor (0, Qcolor (150,0,0));

Pnewitem->setfont (0, Qfont ());

}

Pnewitemroot->setexpanded (TRUE); Expand Child Items

Advanced:

Add checkbox, Icon

Pnewitem->setflags (qt::itemisselectable | qt::itemisusercheckable | qt::itemisenabled);

Pnewitem->setcheckstate (0, qt::unchecked);

Pnewitem->seticon (int, qicon);

Put some QT controls on the item, such as Qspinbox,qcombobox,qpushbutton, etc.

This->setitemwidget (Pnewitem, 0, New Qspinbox ());

Getting the qrect of an item can sometimes be useful, such as thumbnail images:

Qrect rect = This->visualitemrect (qtreewidgetitem*);

Right-click menu rewrite

Contextmenuevent (Qcontextmenuevent * event), or use signal itempressed (qtreewidgetitem*, int);

The right operation, can be initialized with Qlabel or Qtreewidgetitem to the opponent,

Hide Header

Header ()->hide ();

M_pheaderview->setclickable (TRUE); can emit sectionclicked (int) signals, can be a menu,

M_pheaderview->setmovable (TRUE);

M_pheaderview->setresizemode (0, qheaderview::fixed); Fixed column width

M_pheaderview->setdefaultsectionsize (100); Default

Sort

Treewidget->setsortingenabled (TRUE);

Treewidget->header ()->setsortindicatorshown (true);

Treewidget->header ()->setsortindicator (0, Qt::ascendingorder);

Treewidget->header ()->setsectionhidden (1, true);//Hide Column

To customize, use the signal.

Connect (Treewidget->header (), SIGNAL (sectionclicked (int)), this, SLOT (sectionclickedslot (int)));

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.