Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>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.</p> <p><a href="http://doc.qt.nokia.com/4.7-snapshot/itemviews-frozencolumn.html" rel="nofollow">http://doc.qt.nokia.com/4.7-snapshot/itemviews-frozencolumn.html</a></p> <ol> <li><p>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.</p></li> <li><p>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.</p></li> <li><p>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.</p></li> <li><p>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, <a href="http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qwidget.html#resizeEvent" rel="nofollow">http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qwidget.html#resizeEvent</a>. So I had to override this method in my class to set the headers on both tables to the same width.</p></li> </ol> <p>Code:</p> <pre><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) </code></pre> <ol start="5"> <li>Override the selectAll() method so when a user clicks the corner button, if enabled, all data in both tables will be selected:</li> </ol> <p>Code:</p> <pre><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) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload