Results 1 to 3 of 3

Thread: QComboBox in QTableWidget : display troubles.

  1. #1
    Join Date
    Feb 2007
    Posts
    158
    Thanks
    25
    Qt products
    Qt4
    Platforms
    Windows

    Default QComboBox in QTableWidget : display troubles.

    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

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QComboBox in QTableWidget : display troubles.

    What happens if you pass the table as parent when you create liste_section?

  3. #3
    Join Date
    Feb 2007
    Posts
    158
    Thanks
    25
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QComboBox in QTableWidget : display troubles.

    Qt Code:
    1. // Creating the item 6/6 for this row (A list of choices)
    2. QComboBox *liste_section = new QComboBox(tableau_regles);
    To copy to clipboard, switch view to plain text mode 

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

Similar Threads

  1. QComboBox inside QTableWidget
    By campana in forum Qt Programming
    Replies: 7
    Last Post: 20th March 2006, 18:22

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.