PDA

View Full Version : size of QTableWidgetItem will not change



comme
3rd May 2012, 17:46
Hi
I have a problem with changing the width of QTableWidgetItems.
here's a picture of the problem:
7669
there are 3 columns. The blue lines mark the width of the items in question.
The width will not change after calling QTableView::setColumnWidth() or giving the item a sizeHint, or resizing the QComboBox itself before or after any of these calls.
setDefaultSectionSize() works, but is unsuitable because the first column has to be wider than the other two.
Setting the width of the first column doesn't work either, and I don't know the width of the text in pixels so I can remove the empty space marked by the red line.
So it won't work with or without a cell widget.
What I need is something like this:
7671

Here's the code I currently use to create a row in the table:


if(this->QTableWidget::columnCount() != 3) {
this->table_widget::set_column_count(3, false); //calls setColumnCount
this->setColumnWidth(0, 200); //does not work
this->setColumnWidth(1, 40); //neither does this
this->setColumnWidth(2, 40); //...
}
this->QTableWidget::insertRow(this->cur_index); //cur_index = current row
this->QTableWidget::setItem(this->cur_index, 0, new dfts::var_table_item(*var, flags));
this->QTableWidget::setItem(this->cur_index, 1, new dfts::var_table_item);
this->QTableWidget::setItem(this->cur_index, 2, new dfts::var_table_item);
this->set_cell_widget(this->cur_index, 1, create_default_color_combobox(QSize(40, 0))); //create a combobox size 40:constructor-default
this->set_cell_widget(this->cur_index, 2, create_default_color_combobox(QSize(40, 0)));

horizontal and vertical headers are set invisible, in case that matters.

So my question is: why can't I control the width of these columns?

rvega
3rd May 2012, 22:22
Are you missing the table_widget reference in

this->setColumnWidth(0,200)

ChrisW67
4th May 2012, 09:19
Some of the oddest coding I have seen for a while.

Anyway, try:


horizontalHeader()->resizeSection(0, 200);
horizontalHeader()->resizeSection(1, 20);
horizontalHeader()->resizeSection(1, 20);