PDA

View Full Version : Different widths for each column in different row in QTableWidget - Qt5



KalyanP
16th March 2017, 06:06
Hi,

I am creating a QTableWidget with multiple rows and columns.
And inserting custom QWidgets into the table.
These custom widgets are having diff. widths.

I am giving the below settings for the QTableWidget:

QTableWidget *m_pTimelineTable = new QTableWidget();

m_pTimelineTable->setRowCount(m_masterLayout.sRowCount);
m_pTimelineTable->setColumnCount(m_masterLayout.sColCount);

m_pTimelineTable->horizontalHeader()->hide();
m_pTimelineTable->verticalHeader()->hide();

m_pTimelineTable->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents );
m_pTimelineTable->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents );

m_pTimelineTable->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOf f);
m_pTimelineTable->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff) ;
...
...
//Custom Widget
MyView *mView = new MyView(); //Inherited from QWidget
int iCustomWidth = 600;
mView->setGeometry(0,0,iCustomWidth,250);

//This iCustomWidth will be different for each custom widget
...
...
m_pTimelineTable->setCellWidget((*bIterator).row_num, (*bIterator).col_num, mView);[/I][/I]


Now, all CustomWidgets in each cell of the QTableWidget is having the same width.

Anyone, could you please suggest me to get the diff. widths of custom widgets in each cell ...

Thanks
Kalyan

Santosh Reddy
16th March 2017, 06:58
Do you want to set the cell width or widget width?

or

Do you want to set the cell width and fit the widget to the cell width ?


All cells in a column will have same width, you can try setting column span for the cell.

KalyanP
16th March 2017, 09:10
Do you want to set the cell width or widget width?

or

Do you want to set the cell width and fit the widget to the cell width ?


All cells in a column will have same width, you can try setting column span for the cell.

Yes...exactly...I am looking for "set the cell width and fit the widget to the cell width".

If not with QTableWidget, is there any other widget/layout to achieve this ?

Thanks

Santosh Reddy
16th March 2017, 10:58
For different width cells you will have to use column span.

KalyanP
20th March 2017, 13:53
Thank You Santosh.