PDA

View Full Version : QComboBox in QTableWidget : display troubles.



Nyphel
13th October 2007, 22:47
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 :


void interface_impl::SLOT_ajouter_regle()
{
// Adding a new row in my QTableWidget
tableau_regles->setRowCount(tableau_regles->rowCount() + 1);

// Creating the item 1/6 for this row (A checkbox)
QTableWidgetItem *Item_0 = new QTableWidgetItem("");
Item_0->setCheckState(Qt::Unchecked);
Item_0->setFlags(Item_0->flags() & (~(Qt::ItemIsEditable)));

// Creating the item 2/6 for this row (Just a message)
QTableWidgetItem *Item_1 = new QTableWidgetItem("Remplacer");

// Creating the item 3/6 for this row (An input field)
QLineEdit *ancienne_valeur = new QLineEdit("");

// Creating the item 4/6 for this row (Just a message)
QTableWidgetItem *Item_3 = new QTableWidgetItem("par");

// Creating the item 5/6 for this row (Another input field)
QLineEdit *nouvelle_valeur = new QLineEdit("");

// Creating the item 6/6 for this row (A list of choices)
QComboBox *liste_section = new QComboBox();
liste_section->addItem("uniquement en début de nom", "start");
liste_section->addItem("partout dans le nom", "full");
liste_section->addItem("uniquement en fin de nom", "end");
liste_section->setCurrentIndex(1);
//liste_section->setSizeAdjustPolicy(QComboBox::AdjustToMinimumCont entsLengthWithIcon);
liste_section->setSizeAdjustPolicy(QComboBox::AdjustToContents);

// Adding items 1 to 6 in the new row of the QTableWidget :
tableau_regles->setItem(tableau_regles->rowCount()-1, 0, Item_0);
tableau_regles->setItem(tableau_regles->rowCount()-1, 1, Item_1);
tableau_regles->setCellWidget(tableau_regles->rowCount()-1, 2, ancienne_valeur);
tableau_regles->setItem(tableau_regles->rowCount()-1, 3, Item_3);
tableau_regles->setCellWidget(tableau_regles->rowCount()-1, 4, nouvelle_valeur);
tableau_regles->setCellWidget(tableau_regles->rowCount()-1, 5, liste_section);

// Resizing each column to the content
resizer_tableaux();
}


Here is my other function, called to resize the columns :


void interface_impl::resizer_tableaux()
{
tableau_regles->update();
tableau_regles->resizeColumnToContents(0);
tableau_regles->resizeColumnToContents(1);
tableau_regles->resizeColumnToContents(2);
tableau_regles->resizeColumnToContents(3);
tableau_regles->resizeColumnToContents(4);
tableau_regles->resizeColumnToContents(5);
}


And here you can see the result :

http://membres.lycos.fr/nyphel/erreur_1.JPG

http://membres.lycos.fr/nyphel/erreur_2.JPG

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 :)

marcel
13th October 2007, 23:16
What happens if you pass the table as parent when you create liste_section?

Nyphel
13th October 2007, 23:29
// Creating the item 6/6 for this row (A list of choices)
QComboBox *liste_section = new QComboBox(tableau_regles);


When I read your idea, I said me : "Of couuuurse !" :D
Unfortunatly, rhe result is exactly the same :(.