Home > Mobile >  How to let QTableWidget default as far as possible, show all the columns
How to let QTableWidget default as far as possible, show all the columns

Time:11-30

 
MyTable: : MyTable (QWidget * parent) : QWidget (parent)
{
InitUI ();
}

Void MyTable: : initUI ()
{
QHBoxLayout * hMainLayout=new QHBoxLayout ();
SetLayout (hMainLayout);
QVBoxLayout * vLeftLayout=new QVBoxLayout ();
QSplitter * vRightSplitter=new QSplitter (Qt: : Vertical);
HMainLayout - & gt; AddLayout (vLeftLayout);
HMainLayout - & gt; AddWidget (vRightSplitter);

MTableWidget=new QTableWidget (100, 10);
MTextEdit=new QTextEdit ();
VRightSplitter - & gt; AddWidget (mTableWidget);
VRightSplitter - & gt; AddWidget (mTextEdit);
VRightSplitter - & gt; SetStretchFactor (0, 2);
VRightSplitter - & gt; SetStretchFactor (1, 1);

MButtonSetTableHead=new QPushButton (" set the header ");
MButtonSetRowNum=new QPushButton (" set of rows ");
MSpinRowNum=new QSpinBox ();
MSpinRowNum - & gt; SetMinimum (0);
MSpinRowNum - & gt; SetMaximum (100000);
QHBoxLayout * hLayout1=new QHBoxLayout ();
HLayout1 - & gt; AddWidget (mButtonSetRowNum);
HLayout1 - & gt; AddWidget (mSpinRowNum);
MButtonInitTable=new QPushButton (" initialization table data ");
MButtonInsertRow=new QPushButton (" insert row ");
MButtonAddRow=new QPushButton (" add ");
QHBoxLayout * hLayout2=new QHBoxLayout ();
HLayout2 - & gt; AddWidget (mButtonInsertRow);
HLayout2 - & gt; AddWidget (mButtonAddRow);
MButtonDeleteCurrentRow=new QPushButton (" to delete the current line ");
MButtonAutoAdjustRowHeight=new QPushButton (" automatic adjustment line height ");
MButtonAutoAdjustColumnWidth=new QPushButton (" automatically adjust the column width ");
QHBoxLayout * hLayout3=new QHBoxLayout ();
HLayout3 - & gt; AddWidget (mButtonAutoAdjustRowHeight);
HLayout3 - & gt; AddWidget (mButtonAutoAdjustColumnWidth);
MButtonReadTableDataToText=new QPushButton (" content to the text read form ");
QHBoxLayout * hLayout4=new QHBoxLayout ();
QHBoxLayout * hLayout5=new QHBoxLayout ();
QHBoxLayout * hLayout6=new QHBoxLayout ();
Editable mCheckEnableEdit=new QCheckBox (" form ");
MCheckSpaceRowBaseColor=new QCheckBox (" line interval impression ");
MCheckShowTableHead=new QCheckBox (" display row header ");
MCheckShowColumnHead=new QCheckBox (" display list head ");
MRadioRowSelect=new QRadioButton (" select ");
MRadioCellSelect=new QRadioButton (" cell selection ");
HLayout4 - & gt; AddWidget (mCheckEnableEdit);
HLayout4 - & gt; AddWidget (mCheckSpaceRowBaseColor);
HLayout5 - & gt; AddWidget (mCheckShowTableHead);
HLayout5 - & gt; AddWidget (mCheckShowColumnHead);
HLayout6 - & gt; AddWidget (mRadioRowSelect);
HLayout6 - & gt; AddWidget (mRadioCellSelect);
QGroupBox * groupBox=new QGroupBox ();
GroupBox - & gt; SetSizePolicy (QSizePolicy: : Fixed, QSizePolicy: : Fixed);
GroupBox - & gt; SetLayout (hLayout6);
VLeftLayout - & gt; AddWidget (mButtonSetTableHead);
VLeftLayout - & gt; AddLayout (hLayout1);
VLeftLayout - & gt; AddWidget (mButtonInitTable);
VLeftLayout - & gt; AddLayout (hLayout2);
VLeftLayout - & gt; AddWidget (mButtonDeleteCurrentRow);
VLeftLayout - & gt; AddLayout (hLayout3);
VLeftLayout - & gt; AddWidget (mButtonReadTableDataToText);
VLeftLayout - & gt; AddLayout (hLayout4);
VLeftLayout - & gt; AddLayout (hLayout5);
VLeftLayout - & gt; AddWidget (groupBox);
VLeftLayout - & gt; AddStretch (1);
}

CodePudding user response:

Run the program now only shows two columns, the need to drag the big window

CodePudding user response:

This is "Qt5.9 c + + development guide" in the fourth chapter of the book

CodePudding user response:

Baidu a Qtablewidget adaptive width
  •  Tags:  
  • Qt
  • Related