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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T13:00:29+00:00 2026-06-02T13:00:29+00:00

I have a QTableView and some content in it. I want a behavior like

  • 0

I have a QTableView and some content in it. I want a behavior like horizontalHeader() -> setResizeMode( ResizeToContent ) but it must not create horizontal scrollbars – I mean the viewport must not be wider than the table.

Even with creating a new QHeaderView it’s not so easy, since there are only a few virtual methods.

drawing to visualize the problem

Thanks in advance,

Charly

PS: I have a custom item delegate, which shortens the long texts with “…”. It returns as sizeHint() the full size, but when the paint() method receives a smaller size (e.g. simulated with resizeMode() == Qt::Interactive) it crops the content.

  • 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-02T13:00:35+00:00Added an answer on June 2, 2026 at 1:00 pm

    New Answer

    You need to set the stretch on individual sections, I’ve created a simple test app:

    Screen shot of test

    test.cpp

    #include <QtGui>
    
    int main(int argc, char** argv)
    {
        QApplication app(argc, argv);
    
        QStandardItemModel mdl(3, 3); // rows, cols
        mdl.setHorizontalHeaderLabels(QStringList() << "Name" << "Size" << "Date");
        mdl.setItem(0, 0, new QStandardItem("Short name"));
        mdl.setItem(0, 1, new QStandardItem("25kb"));
        mdl.setItem(0, 2, new QStandardItem("2011/07/05"));
        mdl.setItem(1, 0, new QStandardItem("This is a long name"));
        mdl.setItem(1, 1, new QStandardItem("25kb"));
        mdl.setItem(1, 2, new QStandardItem("2011/07/05"));
        mdl.setItem(2, 0, new QStandardItem("This is a long long long long name"));
        mdl.setItem(2, 1, new QStandardItem("25kb"));
        mdl.setItem(2, 2, new QStandardItem("2011/07/05"));
    
    
        QTableView view;
        view.setModel(&mdl);
        QHeaderView* hdr = view.horizontalHeader();
        hdr->setResizeMode(0, QHeaderView::Stretch);
        hdr->setResizeMode(1, QHeaderView::ResizeToContents);
        hdr->setResizeMode(2, QHeaderView::ResizeToContents);
    
        view.show();
        return app.exec();
    }
    

    test.pro

    QT += core gui
    SOURCES=test.cpp
    

    Notice: It’s important that void QHeaderView::setResizeMode(int, ResizeMode) is called when when this logical index exists, that is, when a model which defines these columns is attached to the view.


    Old Answer

    QAbstractScrollArea has the horizontalScrollBarPolicy property which can have the option ScrollBarAlwaysOff.

    Try something like:

    QAbstractScrollArea* scrollArea = // ???
    scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    

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

Sidebar

Related Questions

I want to create a subclass of UITableView or UIScrollView that will have some
I have a UINavigationController consisting of a tableview I want to load some data
i have been trying to figure this out but i just can't.... for some
I have a QTableView which has some QString based items in its model. I
I have some table cells displaying different time. I want the time to be
I have two QTableView which one has 10 rows and the other is empty.
I have a QTableView that I need to get the selectionChanged event from. I
Let's say I have a QTableView with a corresponding model. This view shows numbers
Hello i have tableview with many objects in it. If i want to add
i have a tableview which has image and a text behind, i create the

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.