Getting header names from QTreeWidget (Qt)

Last edited on

How to get a QTreeWidget's column names

Here is an example you can run using the itemviews example. The QTreeWidget is in the lower rightmost section. To adapt this script for your own application, use the "picker" eyedropper to find out the object's symbolic name in your application and replace the name with it in your own script.

function main()

    // hardcoded object name
    var name = {"aboveWidget": names.Item_Views_qt_splithandle_QSplitterHandle, "type": "QTreeWidget",
    "unnamed": "1", "visible": "1", "window": names.ItemViews_MainWindow};
    var treeWidget = waitForObject(name);
    var header = treeWidget.headerItem();
    test.log("total columns: " + header.columnCount());
    for (i = 0; i < header.columnCount(); i++) {
        test.log("column #" + i + ": " + header.text(i));