Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9097947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T00:14:41+00:00 2026-06-17T00:14:41+00:00

During runtime I have inserted QCombobox in my QTreeWidget like this: //global defines #define

  • 0

During runtime I have inserted QCombobox in my QTreeWidget like this:

    //global defines
    #define COLUMN_1 (0)
    #define COLUMN_2 (1)

    //Init QComboBox to QTreeWidget - works fine.
    QTreeWidgetItem *item = new QTreeWidgetItem(_myTreeWidget);
    item->setText(COLUMN_1,"testing");

    QComboBox *box = new QComboBox();

    box->addItem("select1");
    box->addItem("select2");
    box->addItem("select3");

    _myTreeWidget->setItemWidget(item, 1, box);

The above code works, but I also want to read the data text in these columns. Eg. get the strings “testing” & “select2” from code above. The problem is that I can’t figure out how to read the “QComboBox::currentText()” in the comboboxes.
I have tried:

   QTreeWidgetItemIterator it(_myTreeWidget);
   while(*it)
   {
      QTreeWidgetItem *item = *it;

      QVariant first   = item->text(COLUMN_1);
      QString firstStr = loggerName.toString();  //this works

      QComboBox *box    = (QComboBox*)item->data(COLUMN_2, 0);   
      QString boxValStr = box->text().toString();   //this doesn't works, always empty string

      //... more code to handle strings... 

      it++;
   }

Feels like the “item->data(COLUMN_2, 0)” is wrong way to go cause it returns a QVariant.
Solution on this problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T00:14:42+00:00Added an answer on June 17, 2026 at 12:14 am

    Solved it thanks to the help from @Umnyobe and @Zaiborg above. Here is a total working example:

    Init QTreeWidget with text in column1 and QComboBox in column2:

    //global defines
    #define COLUMN_1 (0)
    #define COLUMN_2 (1)
    
    QTreeWidgetItem *item = new QTreeWidgetItem(_myTreeWidgetPtr);//item to put in tree
    item->setText(COLUMN_1,"animal");                             //item for column 1 in the tree.
    
    QComboBox *box = new QComboBox();
    box->addItem("mouse");                                        //adds selections for comboboxes
    box->addItem("cat");
    box->addItem("dog");
    
    _myTreeWidgetPtr->setItemWidget(item, COLUMN_2, box);           //insert items in tree.
    

    Read values from tree:

    QTreeWidgetItemIterator it(_myTreeWidgetPtr);
    while(*it)
    {
        QTreeWidgetItem *item = *it;
    
        //Init pointer to current combobox
        QComboBox* box = qobject_cast<QComboBox*>(_myTreeWidgetPtr->itemWidget(item, COLUMN_2)); 
    
        //Get data from QTreeWidget
        QString col1Str = item->text(COLUMN_LOGGER);   
        QString col2Str = box->currentText();
    
        it++;
    }
    

    hope it can help someone 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created two views using multiview option. Now during runtime, I'm getting this
I have a stackpanel with some usercontrols that are added or removed during runtime.
i am adding more than one link button during runtime but they all have
i am trying to modify during runtime an image in my application, this image
I have .jar file which during runtime reads one .dylib library which I compiled
I have an application where I'm adding controls during runtime and want to attach
I am trying to validate textbox values during runtime in vb.net I have following
I have a simple html snippet that I add to the document during runtime.
I have the following code: vector<vector<Obj> > vectObjVects(10); vectObjVects[0].reserve(100); During runtime, at the third
I have JSF + Hibernate app. During runtime, i need to change database, to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.