Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Set Default Selected item for QCombox from QTreeWidget ( QTreeWidget is inside QCombobox )
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 3.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    frsdot
    wrote on last edited by
    #1

    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);
    }

    1 Reply Last reply
    0
    • J Offline
      J Offline
      jakakishan
      wrote on last edited by
      #2

      cmb = new QComboBox(this);

      Jkishan

      1 Reply Last reply
      0
      • F Offline
        F Offline
        frsdot
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved