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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:44:20+00:00 2026-05-26T22:44:20+00:00

I’ve got a QTableView with a custom model, and it works fine. However, when

  • 0

I’ve got a QTableView with a custom model, and it works fine. However, when I start the program, I want the rows and columns to be sized to fit because by default they take up too much space. I should note that my table has 65k rows (only 3 columns), and they’re always the same. The following code works fine, but is very slow.

memorListView is a QTableView. Prior to this line, I setModel to my custom model

memoryListView->resizeRowsToContents();
memoryListView->resizeColumnsToContents();

Like I mentioned, this does exactly what I need, but it takes about 8 seconds to run. I presume it’s because all the data needs to be pulled out of the model, when the view is otherwise happy to be lazy about requesting it.

I could set the row and column size manually, which is my current workaround, but this is a cross-platform app and I’d like to not have to worry about different widgets, text sizes, DPIs, etc causing a problem. I could autosize one row and then set the rest to that row’s size, which would be correct but seems very hacky.

I’m hoping that I’m just doing this naively, and there’s some option I can toggle that’ll make it faster. I know all rows and columns will be the same size; can I tell it to use that hint somehow?

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-26T22:44:20+00:00Added an answer on May 26, 2026 at 10:44 pm

    You could simply measure the width of the text using QFontMetrics, then set the column width to it. Something like that should work:

    QFontMetrics fontMetrics(yourWidget->font());
    int columnWidth = fontMetrics.width("some text");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
Specifically, suppose I start with the string string =hello \'i am \' me And
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
i want to parse a xhtml file and display in UITableView. what is the
i got an object with contents of html markup in it, for example: string

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.