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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:35:37+00:00 2026-05-28T15:35:37+00:00

I am a student programmer and I am using Qt to build a GUI

  • 0

I am a student programmer and I am using Qt to build a GUI interface for work. I have a QTreeWidget that has a total of 8 Columns. The input that needs to be entered into each one of these columns is fairly small. In that regard, I was trying to find a way to re-size all of the columns to the least amount of space required. much like the action that is performed when you click on the dividers. I have looked over several websites and the Qt documentation and haven’t found a solution. After looking over the documentation it seems that there are a bunch of ways to do this but I cant get one to work. I am beginning to think that I need to enable/disable something somewhere. It’s as if the changes I write in to my build function (This function clears the table; Reads data from my vector, displays certain data in the table, and then is suppose to re-size the headers/columns to just enough size to fit the contents of the column) are not even applied. I have tried the following with no changes:

        ui->treeWidgetInjections->setColumnWidth(i, minimumWidth());
        ui->treeWidgetInjections->resizeColumnToContents(i);
        ui->treeWidgetInjections->header()->ResizeToContents;
        ui->treeWidgetInjections->header()->resizeSection(i, minimumWidth());

All of these are in the end of of my build Function (unrelated info removed):

ui->treeWidgetInjections->clear();
    for (int i=0; i < qTreeInjectionData.size(); i++)
        {
            //fill Qtree with items;
            //fill QTree items with data;
            //re size function here;
        }

Please only leave productive feedback as I am only interested in learning and overcoming this challenge. Thanks in advance!

  • 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-28T15:35:38+00:00Added an answer on May 28, 2026 at 3:35 pm

    This minimal example works for me:

    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
    
        QVBoxLayout *layout = new QVBoxLayout(centralWidget());
        QTreeWidget *tree = new QTreeWidget(this);
        layout->addWidget(tree);
    
        tree->setColumnCount(3);
    
        QStringList first, second, third;
        first  << "xxxxxxxxx"      << "xxxxxxxxxxxxx"     << "xxxxxxxx";
        second << "xxxxx"          << "xxxxxxxxxxxxxxxxx" << "xxxxx";
        third  << "xxxxxxxxxxxxxx" << "xxxxxxxxxx"        << "xxxxxxxx";
    
        tree->insertTopLevelItem(0, new QTreeWidgetItem(first));
        tree->insertTopLevelItem(0, new QTreeWidgetItem(second));
        tree->insertTopLevelItem(0, new QTreeWidgetItem(third));
    
        for(int i = 0; i < 3; i++)
            tree->resizeColumnToContents(i);
    }
    

    All you need to do is call the resizeColumnToContents() method once for every column after you populate the view. Let me know if the problem persists.

    • 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 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 student programmer and I am using Qt to develop a GUI interface
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'm a student programmer and I'm using Qt to create a Gui that gets
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

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.