Hey Guys,

i'm pretty new to QT - actually i'm using QT Jambi. I am stuck solving this problem:

i am building a QWidget which gets it's content from a generated QUiForm. This consists mainly of a QGridLayout, which i want to refill on resize. So what i have to do is either clean the QGridLayout and fill it with my new "icons" or swap the old QGridLayout with a new one.

The Problem is - that i can't do either. It seems that QT Jambi has no method for a QLayout to clear all items. Also my attempts to just swap the old with the new one did not work. It seems, that nor can't i remove the old one, but neither can i swap it with giving it a new layout. It says:"QLayout: Attempting to add QLayout "" to QWidget "Overview", which already has a layout"

Here's my code:


Qt Code:
  1. private void rearrangeIcons(QSize size){
  2. int anzahlReihen = size.width()/55;
  3. int anzahlZeilen = size.height()/70;
  4. int gesamt = anzahlReihen * anzahlZeilen;
  5. QGridLayout layout = new QGridLayout(install_base.parent);
  6.  
  7. int row = 0;
  8. int column = 0;
  9. int current = 0;
  10. for(Entry<String, String> entry : icons.entrySet()){
  11. if(column > anzahlReihen){
  12. column = 0;
  13. row++;
  14. }
  15.  
  16. layout.addLayout(getLabeledIcon(entry.getKey(), entry.getValue()), row, column, 1, 1);
  17. System.out.println("Adding "+entry.getKey()+ " "+ entry.getValue()+" current Index: "+current+ " to Row "+row+" and Column "+column);
  18. column++;
  19. current++;
  20. }
  21.  
  22. while(current < gesamt){
  23.  
  24. if(column > anzahlReihen){
  25. column = 0;
  26. row++;
  27. }
  28.  
  29. layout.addLayout(new QVBoxLayout(), row, column, 1, 1);
  30.  
  31. column++;
  32. current++;
  33. }
  34.  
  35. repaint();
  36. }
  37. }
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. public QGridLayout gridLayout_2;
  2. public QTreeView treeView;
  3. public QLabel label;
  4. public QWidget parent;
  5. public QScrollArea scrollArea;
  6. public QLayout layout;
  7. public QGridLayout currentLayout;
  8.  
  9. public Ui_GridView() { super(); }
  10.  
  11. public void setupUi(QWidget Overview)
  12. {
  13. parent = Overview;
  14. Overview.setObjectName("Overview");
  15. Overview.resize(new QSize(261, 592).expandedTo(Overview.minimumSizeHint()));
  16. layout = new QFormLayout(parent);
  17. }
To copy to clipboard, switch view to plain text mode 

I would be very happy for every help!

Greetings,
Geki