Set Default Selected item for QCombox from QTreeWidget ( QTreeWidget is inside QCombobox )



  • Hello,

    I have set a qTreeWidget inside a QCombo box, it works well. But I am unable to add the default selected item ( say second item with column one's data).

    Here is the code snippet

    cmb = new QComboBox();
    QTreeWidget *treeWidget = new QTreeWidget(cmb);
    cmb->setModel(treeWidget->model());

    treeWidget->setColumnCount(2);
    QTreeWidgetItem *topLevelItem = NULL;

    QTreeWidgetItem *parentItem = topLevelItem;

    for( int row =0; row < 2; row++)
    {

    QPointer<QPushButton> SendBtn= new QPushButton("Send");

    QTreeWidgetItem* item = new QTreeWidgetItem();
    treeWidget->addTopLevelItem(item);

    treeWidget->setItemWidget(item, 0, txtLabel); // Set lable
    treeWidget->setItemWidget(item, 1, SendBtn); // Set push button.

    }

    treeWidget->header()->hide();
    cmb->setView(treeWidget);

    cmb->setModelColumn(0); // Set default text of selected item to column 1 i.e label data ?????????????
    cmb->setCurrentIndex(1); // Select first row ???????????

    Similarly when I use the signal slot mechanism to select an item from QTreeWidget and set inside QCombo box selected item , it does not work either for combo box.

    connect(cmb, SIGNAL(activated(int)), this, SLOT(getComboIndex(int)));

    void TestWidget:: getComboIndex(int index)
    {
    cmb->setModelColumn(1);
    cmb->setCurrentIndex(index);
    }



  • cmb = new QComboBox(this);



  • This does not work either. Moreover , I modified the code so that combo box is created in designer and I reference that combo box.

    In the event
    void TestWidget:: getComboIndex(int index)
    {
    cmb->setModelColumn(1);
    cmb->setCurrentIndex(index);
    }
    treeWidget->currentIndex() --> This does return me a model index whose row and column correspond to the value selected from tree widget. But setting it in combo box seems to be an issue.


Log in to reply
 

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