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 7185255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:22:33+00:00 2026-05-28T18:22:33+00:00

I am currently a student programmer using Qt to build a GUI inteface at

  • 0

I am currently a student programmer using Qt to build a GUI inteface at work and I am currently running into a problem finding a solution in the Qt Documentation On the QTreeWidgetItem. I currently have an interface that has buttons to edit, delete, and copy instances in my QTree. It might be important for you to understand the way my tree is populated. The items displayed in the QTree are dynamically appended from a vector in this way.

void InjectionGUI::addInjections_Clicked() //creates a new instance of injections
{
    InjectionDialog newAddInjectionDialog; //where my dialog opens for user input
    InjectionData defaultValues; 
    newAddInjectionDialog.setData(defaultValues);
            if(newAddInjectionDialog.exec() == QDialog::Accepted)//a check data returns either Accepted or rejected 
            {
               qTableInjectionData.append(newAddInjectionDialog.transInjectionData); //this appends the valid data from the injection dialog to the vector qTableInjectionData
                ui->injectionTreeWidget->clear();
                for (int i=0; i < qTableInjectionData.size(); i++) // here I add the data from the vector to the tree widget.
                    {
                    InjectionData temp = qTableInjectionData.at(i);
                        QString injectionType;
                        QString tmpStr;
                        int column = 0;

                        //need sorting solution(still working on this)
                        if(temp.particleInjectionActive == true) // this evaluates the injection types
                        {
                            if(temp.particleInjectionOrLiquidDroplets == true)
                            {
                                injectionType += "(LD)";
                            }
                            else
                            {
                                injectionType += "(P)";
                            }
                        }
                        if(temp.fluidInjectionActive == true)
                        {
                            injectionType += "(F)";
                        }
                        QTreeWidgetItem *qTreeWidgetItemInjectionData = new QTreeWidgetItem(ui->injectionTreeWidget); //Here data is added into rows from each instance of injection dialog found in vector
                        qTreeWidgetItemInjectionData->setText(column++, tmpStr.setNum(i));
                        qTreeWidgetItemInjectionData->setText(column++, temp.lineEditInjectionName);
                        qTreeWidgetItemInjectionData->setText(column++, injectionType);
                        qTreeWidgetItemInjectionData->setText(column++, tmpStr.setNum(temp.lineEditParitcleVelocity));
                        qTreeWidgetItemInjectionData->setText(column++, tmpStr.setNum(temp.lineEditFluidVelocity));
                        qTreeWidgetItemInjectionData->setText(column++, tmpStr.setNum(temp.lineEditParticleMassFlow));
                        qTreeWidgetItemInjectionData->setText(column++, tmpStr.setNum(temp.lineEditFluidMassFlow));
                        qTreeWidgetItemInjectionData->setText(column++, temp.lineEditComment);
                    }
            }
}

Now I really need a way to find out which item the user has selected in the QTree so that I can have it deleted from the Vector. My psuedo is to identify which row has been selected, confirm delete, delete itemAt(item selected), reassign ID column; because each instance is assigned a number in this column. I was looking over this post, posted three years ago; but it mostly just refers back to the documentation that I have already been reviewing. Plus, the answer that was selected seems extremely inconclusive as the other answer seem to have been on the right track. I understand that this answer might be right in front of me here; but what can i say, noobs will be noobs and I am having a hard time understanding the implementation. Please only leave productive feedback as I am only interested in learning and accomplishing this task.

  • 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-05-28T18:22:34+00:00Added an answer on May 28, 2026 at 6:22 pm

    You need to obtain the selectionModel, then the selected indices and then iterate over them:

    treeWidget->selectionModel()->selection();
      auto idx = sel.indexes();
      foreach(auto index, idx) {
        camModel_->removeRow(index.row());
      }
    }
    

    selectionModel is in QAbstractItemModel. Note the C++11 auto.

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

Sidebar

Related Questions

I am a student programmer using Qt to build a GUI for work. I
I'm a student programmer and I am using Qt to build some GUI applications
Im a student programmer using Qt to develop a GUI for work and I
I am a student programmer using Qt to develop a GUI application. I am
I am a student programmer currently designing a GUI for my company with Qt
I am student programmer and I am using Qt to develop a GUI interface
I currently am a student worker at a medium sized university. i work for
I am a student currently learning about Functional Reactive paradigm using F#. It's radically
I'm a blind student currently in a system admin/shell programming class. Although ssh works
I am an upper level Software Engineering student currently in a Data Structures and

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.