Qtablewidget usage and beautification _ qtablewidget_qtableview scroll bar width and Style

Source: Internet
Author: User

// Create and set attributes
M_tablewidget = new qtablewidget (this );
M_tablewidget-> setrowcount (10 );
M_tablewidget-> setcolumncount (3 );
// M_tablewidget-> setframeshape (qframe: noframe); // set the border
// M_tablewidget-> setshowgrid (false); // set not to display grid lines
// Qpalette PLL = m_tablewidget-> palette ();
// PLL. setbrush (qpalette: Base, qbrush (qcolor (255,255,255, 0 )));
// M_tablewidget-> setpalette (PLL );
// M_tablewidget-> horizontalheader ()-> setstylesheet ("qheaderview: Section {background-color: lightblue; color: black; padding-left: 4px; Border: 1px solid # 6c6c6c ;}");


M_tablewidget-> horizontalheader ()-> setdefasesectionsize (150 );
M_tablewidget-> horizontalheader ()-> setclickable (false); // set the header to be unclickable (sorted by default)

// Set the header content
Qstringlist header;
Header <tr ("Index") <tr ("name") <tr ("time ");
M_tablewidget-> sethorizontalheaderlabels (header );

// Set the header font to bold
Qfont font = m_tablewidget-> horizontalheader ()-> font ();
Font. setbold (true );
M_tablewidget-> horizontalheader ()-> setfont (font );

M_tablewidget-> horizontalheader ()-> setstretchlastsection (true); // you can specify the full table width.
M_tablewidget-> verticalheader ()-> setresizemode (qheaderview: resizetocontents );
M_tablewidget-> verticalheader ()-> setdefasesectionsize (10); // set the line spacing
M_tablewidget-> setframeshape (qframe: noframe); // set no border
M_tablewidget-> setshowgrid (false); // set not to display grid lines
M_tablewidget-> verticalheader ()-> setvisible (false); // sets the vertical header to be invisible.
M_tablewidget-> setselectionmode (q1_actitemview: extendedselection); // You can select multiple values (CTRL, shift, CTRL +)
M_tablewidget-> setselectionbehavior (q1_actitemview: selectrows); // You can select a row each time you select a behavior.
M_tablewidget-> setedittriggers (q1_actitemview: noedittriggers); // The settings cannot be edited.
M_tablewidget-> horizontalheader ()-> resizesection (150); // set the width of the first column of the header
M_tablewidget-> horizontalheader ()-> resizesection (150); // set the width of the first column of the header
M_tablewidget-> horizontalheader ()-> setfixedheight (25); // you can specify the height of the header.

// M_tablewidget-> setstylesheet ("Background: RGB (, 56); Alternate-Background-color: RGB (, 55); selection-Background-color: qlineargradient (X1: 0, Y1: 0, X2: 0, Y2: 1, stop: 0 RGB (56, 56), stop: 1 RGB (, 76 ));"); // set the selected background color
// M_tablewidget-> horizontalheader ()-> setstylesheet ("qheaderview: Section {background-color: qlineargradient (X1: 0, Y1: 0, X2: 0, Y2: 1, stop: 0 RGB (210,210,210, 46), stop: 1 RGB (, 66); color: RGB (); padding-left: 4px; Border: 1px solid #383838;} "); // sets the background color of the header.
M_tablewidget-> setalternatingrowcolors (true );
M_tablewidget-> setfocuspolicy (QT: nofocus); // remove the selected dotted box

// Set the horizontal and vertical scroll bar styles
// M_tablewidget-> horizontalscrollbar ()-> setstylesheet ("qscrollbar {Background: red; Height: 10px ;}"
// "Qscrollbar: handle {Background: lightgray; Border: 2px solid transparent; border-radius: 5px ;}"
// "Qscrollbar: handle: hover {Background: Gray ;}"
// "Qscrollbar: sub-line {Background: transparent ;}"
// "Qscrollbar: Add-line {Background: transparent ;}");
// M_tablewidget-> verticalscrollbar ()-> setstylesheet ("qscrollbar {Background: red; width: 10px ;}"
// "Qscrollbar: handle {Background: lightgray; Border: 2px solid transparent; border-radius: 5px ;}"
// "Qscrollbar: handle: hover {Background: Gray ;}"
// "Qscrollbar: sub-line {Background: transparent ;}"
// "Qscrollbar: Add-line {Background: transparent ;}");
/* Qpalette pal;
Pal. setcolor (qpalette: Base, qcolor (255, 0, 0 ));
Pal. setcolor (qpalette: alternatebase, qcolor (0,255, 0 ));
M_tablewidget-> setpalette (PAL );*/
M_tablewidget-> sethorizontalscrollbarpolicy (QT: scrollbaralwaysoff );
M_tablewidget-> setverticalscrollbarpolicy (QT: scrollbaralwaysoff );
M_tablewidget-> setalternatingrowcolors (true );
M_tablewidget-> setshowgrid (false );

Qtablewidget usage and beautification _ qtablewidget_qtableview scroll bar width and Style

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.