Hello,

My application displays a QTableWidget on its interface.
A buttons connected to a SLOT allows the user to add a row in thes QTableWidget.

Here is the code of this SLOT :
Qt Code:
  1. void interface_impl::SLOT_ajouter_regle()
  2. {
  3. // Adding a new row in my QTableWidget
  4. tableau_regles->setRowCount(tableau_regles->rowCount() + 1);
  5.  
  6. // Creating the item 1/6 for this row (A checkbox)
  7. Item_0->setCheckState(Qt::Unchecked);
  8. Item_0->setFlags(Item_0->flags() & (~(Qt::ItemIsEditable)));
  9.  
  10. // Creating the item 2/6 for this row (Just a message)
  11. QTableWidgetItem *Item_1 = new QTableWidgetItem("Remplacer");
  12.  
  13. // Creating the item 3/6 for this row (An input field)
  14. QLineEdit *ancienne_valeur = new QLineEdit("");
  15.  
  16. // Creating the item 4/6 for this row (Just a message)
  17. QTableWidgetItem *Item_3 = new QTableWidgetItem("par");
  18.  
  19. // Creating the item 5/6 for this row (Another input field)
  20. QLineEdit *nouvelle_valeur = new QLineEdit("");
  21.  
  22. // Creating the item 6/6 for this row (A list of choices)
  23. QComboBox *liste_section = new QComboBox();
  24. liste_section->addItem("uniquement en début de nom", "start");
  25. liste_section->addItem("partout dans le nom", "full");
  26. liste_section->addItem("uniquement en fin de nom", "end");
  27. liste_section->setCurrentIndex(1);
  28. //liste_section->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLengthWithIcon);
  29. liste_section->setSizeAdjustPolicy(QComboBox::AdjustToContents);
  30.  
  31. // Adding items 1 to 6 in the new row of the QTableWidget :
  32. tableau_regles->setItem(tableau_regles->rowCount()-1, 0, Item_0);
  33. tableau_regles->setItem(tableau_regles->rowCount()-1, 1, Item_1);
  34. tableau_regles->setCellWidget(tableau_regles->rowCount()-1, 2, ancienne_valeur);
  35. tableau_regles->setItem(tableau_regles->rowCount()-1, 3, Item_3);
  36. tableau_regles->setCellWidget(tableau_regles->rowCount()-1, 4, nouvelle_valeur);
  37. tableau_regles->setCellWidget(tableau_regles->rowCount()-1, 5, liste_section);
  38.  
  39. // Resizing each column to the content
  40. resizer_tableaux();
  41. }
To copy to clipboard, switch view to plain text mode 

Here is my other function, called to resize the columns :
Qt Code:
  1. void interface_impl::resizer_tableaux()
  2. {
  3. tableau_regles->update();
  4. tableau_regles->resizeColumnToContents(0);
  5. tableau_regles->resizeColumnToContents(1);
  6. tableau_regles->resizeColumnToContents(2);
  7. tableau_regles->resizeColumnToContents(3);
  8. tableau_regles->resizeColumnToContents(4);
  9. tableau_regles->resizeColumnToContents(5);
  10. }
To copy to clipboard, switch view to plain text mode 

And here you can see the result :





1) So, as you can see, when the new row is created my QComboBox is not well displayed.

2) Moreover, when I add another row, the column is resized to fit its content... But the column's width() is too small. I don't understand how should I use the QComboBox and the QTableWidget properties and functions in order to adjust the column size in order to fit the QComboBox's minimal size, when they display all their content. Actually it seems that the resizeColumnToContents() returns the width of the column title.

Thanks for any idea, tip or solution