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

The Archive Base Latest Questions

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

I am a student programmer using Qt to build a GUI for work. I

  • 0

I am a student programmer using Qt to build a GUI for work. I have ran into an issue; more or less and inconvience of sorts wiith multiple selections in the QTreeWidget. My GUI has a main interface with a QTreeWidget as the central item in this window. Below the QTreeWidget I have several buttons; copy, edit, and delete. As you might’ve already guessed each one of these buttons correlates to a function that executes the command. My tree widget has the ability to select multiple items; however, when multiple items are selected the only item that is passed through is the last item that was selected. I was hoping that somebody with some more insight in this IDE might be able to point me in the right direction for accomplishing this. Here is the process that is followed when one of these functions is executed.

void InjectionGUI::copyInjection_Clicked(QTreeWidgetItem *itemToCopy)
{
    InjectionData copyInjectionData;         //first use data from the tree widget row
    QString converter = itemToCopy->text(0); //to find the vector item that will be copied
    int id = converter.toInt();
    int nameNumber;
    copyInjectionData = qTreeInjectionData.at(id);
    qTreeInjectionData.append(copyInjectionData);
    buildTreeWidget();
}

void InjectionGUI::slotInjectionCopy()
{
    if(ui->treeWidgetInjections->currentItem() == 0)
    {
        QMessageBox invalidSelection;
        invalidSelection.setText("No row selected to copy");
        invalidSelection.setWindowTitle("Error");
        invalidSelection.exec();
    }
    else
    {
        copyInjection_Clicked(ui->treeWidgetInjections->currentItem());
    }
}

I’m not too sure what code will be relevant towards making this change; so if there is additional structure that anyone would like to see please just requested. I’m pretty sure that my problem or my solution is going to lie in the way that I’m using current item. After reviewing the documentation from Qt’s website I’m still unsure how I would change this to allow multiple selections to be passed through the function. Please only provide constructive feedback; I’m only interested in learning and accomplishing a solution. Thanks in advance.

UPDATE! SOLVED!!!
Just thought it might be nice to show what this looked like implemented:

QList<QTreeWidgetItem *> items = ui->treeWidgetInjections->selectedItems();
for(int i = 0; i < items.size(); i++)
{
    QTreeWidgetItem *qTreeWidgetitem = new QTreeWidgetItem;
    qTreeWidgetitem = items.at(i);
    copyInjection_Clicked(qTreeWidgetitem);
}
  • 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-28T14:33:22+00:00Added an answer on May 28, 2026 at 2:33 pm

    If you need to know which items are selected, you can use

    QList<QTreeWidgetItem *> QTreeWidget::selectedItems() const
    

    to have a list of all the currently selected items in the tree.
    Then you may call your function once for every item in the list, or you can overload your function to take as argument a QList<QTreeWidgetItem *> and then run through the list inside the called function.

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

Sidebar

Related Questions

I am currently a student programmer using Qt to build a GUI inteface at
I'm a student programmer and I am using Qt to build some GUI applications
I am a student programmer and I am using Qt to build a GUI
I'm a student programmer and I am using Qt to build a GUI for
I'm a student programmer and I am using Qt to build a GUI application.
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 student programmer and I am using Qt to develop a GUI interface
I'm a student programmer and I'm using Qt to create a Gui that gets
I am a student programmer currently designing a GUI for my company with Qt

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.