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

The Archive Base Latest Questions

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

I’d like to have a QTableWidget that has 2 ‘header’ rows. Essentially I’d like

  • 0

I’d like to have a QTableWidget that has 2 ‘header’ rows. Essentially I’d like to have the top 2 rows of the table not scroll vertically. For example:

Header 1 | Header 2
__________________
Header 3 | Header 4
__________________
Data     | Data
__________________
Data     | Data
__________________
Data     | Data
__________________
Data     | Data
__________________

I’d like to prevent any of the 4 headers (first two rows) not scroll off the screen as the user scrolls down.

I don’t see anyway in Qt to add additional header rows or prevent scrolling of a single row. Maybe there is a tricky way to do this by having 2 actual tables and 1 of those tables having a single row which is a header?

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

    I found a way to do this albeit in a somewhat obscure way. I did find a great example on how to do something similar, but with columns instead of header rows.

    http://doc.qt.nokia.com/4.7-snapshot/itemviews-frozencolumn.html

    1. I created two tables, one for the header rows and one for the data. I then hid the horizontal headers for the data table, set the margins/spacing for everything to 0. This squished the tables close enough together to look like a single table.

    2. Make sure to hide the horizontal scroll bars for each individual table and then adding a new scrollbar that connected the two hidden scroll bars. So, when the user scrolls with the stand-alone scrollbar it triggers events on the ‘real’ hidden scroll bars. This way users can only have a single scrollbar to interact with.

    3. I also had to catch all the signals from the QHeaderView class
      and make sure to apply the changes requested by the signals to both tables at the same time.

    4. The trickest part was making sure the width of the vertical header items were the same length in both tables. The width of a vertical header item gets set on an event called resizeEvent, http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qwidget.html#resizeEvent. So I had to override this method in my class to set the headers on both tables to the same width.

    Code:

    def resize(self):
        """
        Called when we know the data table has been setup by Qt so we are
        guaranteed that the headers now have a width, etc.
    
        There is no other way to guarantee that your elements have been sized,
        etc. by Qt other than this event.
        """
    
        # Make the width of the vertical headers on the header table the same
        # size as the initialized width of the data table (data table widths
        # are setup automatically to fit the content)
        width = self._data_table.verticalHeader().width()
        self._header_table.verticalHeader().setFixedWidth(width)
    
    1. Override the selectAll() method so when a user clicks the corner button, if enabled, all data in both tables will be selected:

    Code:

    def selectAll(self):
        """Select all data in both tables"""
    
        for table in [self._header_table, self._data_table]:
            for row in xrange(table.rowCount()):
                for col in xrange(table.columnCount()):
                    item = table.item(row, col)
                    table.setItemSelected(item, True)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a French site that I want to parse, but am running into
I need a function that will clean a strings' special characters. I do NOT
I have some data like this: 1 2 3 4 5 9 2 6
For some reason, after submitting a string like this Jack’s Spindle from a text
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

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.