Friendtable-> setframeshape (qframe: noframe); // you can specify a border.
Friendtable-> sethorizontalheaderlabels (headlist); set the header
Friendtable-> setselectionmode (q1_actitemview: singleselection); set the selected mode to single-Choice
Friendtable-> setselectionbehavior (q1_actitemview: selectrows); select a row each time when selecting behavior
Friendtable-> setshowgrid (false); Do not display grid lines
Friendtable-> setfont (font); set the font
Set form background or transparency
Qpalette pal = musictable-> palette ();
Pal. setbrush (this-> backgroundrole (), qbrush (qpixmap ("images/background.png ")));
Musictable-> setpalette (PAL );
Set the background image, or initialize the qbrush as qcolor to set the background color.
Qpalette PLL = musictable-> palette ();
PLL. setbrush (qpalette: Base, qbrush (qcolor (255,255,255, 0 )));
Musictable-> setpalette (PLL); // Like qtextedit, you can use the style sheet qpalette to modify its background color and background image. Here we set the brush to completely transparent, it can be transparent.
Set transparency Method 2:
Setstylesheet ("background-color: rgba (255,255,255,255)"); // The last parameter controls transparency.
How to add an image to the qtablewidget list
Qtablewidgetitem * cubesheaderitem = new qtablewidgetitem (TR ("cubes "));
Cubesheaderitem-> seticon (qicon (qpixmap ("1.png ")));
Cubesheaderitem-> settextalignment (QT: alignvcenter );
Musictable-> setitem (, cubesheaderitem); // display the image in the first column of the First row
* ******************* Modify the attributes of the header ****************
Musictable-> horizontalheader ()-> resizesection (0,150); // modify the width of the first column in the header to 150.
Musictable-> horizontalheader ()-> setfixedheight (25); // modify the appropriate height of the header
Musictable-> horizontalheader ()-> setstylesheet ("qheaderview: Section {background-color: lightblue; color: black; padding-left: 4px; Border: 1px solid # 6c6c6c ;} "); // set the header font, color, and mode.
Friendtable-> verticalheader ()-> setstylesheet ("qheaderview: Section {background-color: skyblue; color: black; padding-left: 4px; Border: 1px solid # 6c6c6c} "); // you can specify the font color mode of the border items in the column.
I was wondering if there were any existing APIs in QT, but the results were not found and I could only write them myself.
Qtablewidgetitem contains an API for modifying the background color, which can be called directly, and then used to change the color through loop control.
Implementation Code:
Void testtt: changecolor (qtablewidget * tablewidget ){
For (INT I = 0; I <tablewidget-> rowcount (); I ++)
{
If (I % 2 = 0)
{
For (Int J = 0; j <tablewidget-> columncount (); j ++)
{
Qtablewidgetitem * Item = tablewidget-> item (I, j );
If (item)
{
Const qcolor color = qcolor (1, 252,222,156 );
Item-> setbackgroundcolor (color );
}
}
}
}
Use
Insert an item to the table
Qtablewidgetitem * num = new qtablewidgetitem (qtablewidgetitem: type );
Num-> setcheckstate (QT: unchecked); // Add the check box
Num-> seticon (qicon ("images/fetion.png"); // Add the icon
Num-> settext (infolist. at (I). Name );
Num-> setfont (font );
Num-> settextcolor (color );
Num-> setflags (Num-> flags () ^ QT: itemiseditable );
Int currentrow = friendtable-> rowcount (); // insert to the end
Friendtable-> insertrow (currentrow );
Friendtable-> setitem (currentrow, 0, num); // insert this item
Friendtable-> selectrow (0); select the first row
Delete a row or column
Friendtable-> removerow (ROW );
Friendtable-> removecolumn (column );
Signal
Void cellactivated (INT row, int column)
Void cellchanged (INT row, int column)
Void cellclicked (INT row, int column)
Void celldoubleclicked (INT row, int column)
Void cellentered (INT row, int column)
Void cellpressed (INT row, int column)
Void currentcellchanged (INT currentrow, int currentcolumn, int previusrow, int previuscolumn)
Void currentitemchanged (qtablewidgetitem * Current, qtablewidgetitem * Previous) the item
Void itemactivated (qtablewidgetitem * item)
Void itemchanged (qtablewidgetitem * item)
Void itemclicked (qtablewidgetitem * item)
Void itemdoubleclicked (qtablewidgetitem * item)
Void itementered (qtablewidgetitem * item)
Void itempressed (qtablewidgetitem * item)
Void itemselectionchanged ()
Remove the default row number from QT qtablewidget.
The qtablewidget control automatically dragged out by qtoolbox contains its own row number. It sometimes needs to be removed. It was not found in this place last year. Today we found the relevant method and recorded it.
As shown above, the serial number is provided on the left by default at the beginning.
Qheaderview * headerview = table name-> verticalheader ();
Headerview-> sethidden (true );
Add the code above to remove the row number on the left.
Http://hi.baidu.com/buptyoyo/blog/item/bb8cab3d93817ec97d1e7143.html
Set the row's default height
Tablewidget-> verticalheader ()-> setdefasesectionsize (height)
Beautification of qtablewidget