Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-102034

Merely subclassing QHeaderView causes it to lose built-in functionality

    XMLWordPrintable

Details

    Description

       

      class CustomHeaderView : public QHeaderView {
      	Q_OBJECT
      
      public:
      	CustomHeaderView(Qt::Orientation orientation, QWidget *parent = nullptr) : QHeaderView(orientation, parent) {}
      }
      
      // ...
      
      QTableView view;
      view->setHorizontalHeader(new CustomHeaderView(Qt::Horizontal), &view);
      

       

      This causes the following functionality to disappear:

      • Hover effects
      • Bold header text on selected column
      • Clicking the header selects the whole column

       

      Since no new behaviour was implemented and no methods were overridden, I would expect it to behave exactly like a vanilla QHeaderView.

       

      EDIT: Actually not a bug. QTableView calls `setSectionsClickable(true)` and `setHighlightSections(true)` on the QHeaderViews upon initialization. Custom header views must do the same to retain the default behaviour.

      Attachments

        1. QHeaderView_reimplemented.7z
          2 kB
          Andreas Nicolai
        2. Qt_Support_Request_QHeaderView_custom_painting.pdf
          139 kB
          Andreas Nicolai
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            skoh-qt Sze Howe Koh
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes