How to set the width of one column in treeview to be fixed and the other colume to be auto fit while window resized?



  • One problem in coding with treeview:
    @public class ReportGrid extends QTreeWidget {
    public ReportGrid (QWidget parent) {
    super(parent);
    this.setRootIsDecorated(false);
    this.setAlternatingRowColors(true);
    ArrayList<String> labels = new ArrayList<String>();
    labels.add("Description");
    labels.add("Requird");
    this.setHeaderLabels(labels);
    header().setResizeMode(QHeaderView.ResizeMode.Interactive);
    //this.setModel(model);
    this.setColumnWidth(0, 200);
    this.setColumnWidth(1, 20);
    }
    }@
    I want set the "Description" column 200px min width and "Required" column to be 20px width fixed(it contains an icon).
    But while window resizing the column “Requird” expands.
    Thanks.



  • use header().setStretchLastSection(true);
    and remove header().setResizeMode(QHeaderView.ResizeMode.Interactive);


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.