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

  • Home
  • SEARCH
  • 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 6673849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:40:35+00:00 2026-05-26T03:40:35+00:00

I have a subclass class TableModel : public QAbstractTableModel I override the headerData method

  • 0

I have a subclass

class TableModel : public QAbstractTableModel

I override the headerData method as follow:

QVariant TableModel::headerData(int section, Qt::Orientation orientation, int role) const
{
   if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {...}
   if (role == TableModel::CurrencyRole && orientation == Qt::Horizontal) {...}
   return QVariant();
}

I have a method that set a QTableView as follow using TableModel* table

void A::SetDisplay(QTableView* table_view, QString filter, int role, int sort_role)
{
  proxyModel = new QSortFilterProxyModel(this);
  proxyModel->setSourceModel(table);
  proxyModel->setDynamicSortFilter(true);
  proxyModel->setSortRole(sort_role);
  table_view->setModel(proxyModel);
  table_view->setSortingEnabled(true);
  table_view->setSelectionBehavior(QAbstractItemView::SelectRows);
  table_view->horizontalHeader()->setStretchLastSection(true);
  table_view->verticalHeader()->hide();
  table_view->setEditTriggers(QAbstractItemView::NoEditTriggers);
  table_view->setSelectionMode(QAbstractItemView::SingleSelection);
  proxyModel->setFilterRegExp(QRegExp(filter, Qt::CaseInsensitive));
  proxyModel->setFilterKeyColumn(1);
  proxyModel->sort(0, Qt::AscendingOrder);
  connect( table_view->selectionModel(),
    SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
    this, SIGNAL(selectionChanged(QItemSelection)));
}

I have two QTableView objects ViewA and viewB. I need ViewA to have a header with role == Qt::DisplayRole and viewB to have a header with role == TableModel::CurrencyRole. How can I get the headerData to change for each view using the role.

Thanks, and please let me know if I left any detail out or or something is unclear in my question.

  • 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-26T03:40:36+00:00Added an answer on May 26, 2026 at 3:40 am

    First of all, it looks like to do exactly what you’re trying to to is going to be a bit tricky.

    After a quick perusal of the Qt source code it looks like there’s no way to change what role is passed to your model’s headerData() function just using the API.

    You do, however, have the ability to subclass QHeaderView and override the virtual paintSection() function and then do whatever you want. You’ll probably need to look over Qt’s implementation of this function for reference of how to implement it properly.

    At this point you can set the header view on your views to your new custom one, and then set some internal flag from your view that tells it how to properly call headerData() with the role you want.

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

Sidebar

Related Questions

If subclass in objective-c wants to override a super class's method, does it have
I have an abstract class called Grouping. I have a subclass called GroupingNNA. public
I have the following class subclass of FilterInputStream with only one method overrided. However
I have a class like this : public class SubClass <T> extends SuperClass<Collection<T>>{ public
I have a File class that has an Open() method. I have a subclass
HI All. I have subclass of UIScrollView. IN this class I have added some
In Java, I have a subclass Vertex of the Java3D class Point3f . Now
I have a class A and write a subclass B. A has only one
I have a ConfiguracaoDaApp class in my project that is a NSManagedObject subclass. I
Suppose I have a base class named Visitor, and it has 2 subclass Subscriber

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.