Re: Subclassing QHeaderView
Re: Subclassing QHeaderView
I want to make widget for each sections to fit in size. So I want to wait for signal sectionCountChange then add as many custom widget as count. Layout will place them according to their sizeHint (or which other size function) - layout will keep control of placing widget so they will overlap QHeaderView default sections. I won't need to keep eye on their placement by my self.
Re: Subclassing QHeaderView
That's an incorrect approach. If you want to replace headers with widgets completely then subclass the view, hide the header, use QAbstractScrollArea::setViewportMargins() to make space over the viewport and then create a set of widgets, optionally put them in a layout and place over the viewport instead of the header view. You'll have to reimplement resizeEvent for the view to position your pseudo-header properly when the view is resized. Furthermore it is a good idea to monitor changes in widget sizes and resize the columns of the view appropriately.
A different approach would be to indeed subclass QHeaderView but not use any layouts. Instead attach to appropriate events and signals and position all the widgets manually using QHeaderView::sectionSize().
Re: Subclassing QHeaderView
That's what I was afraid - lots of small things to keep eye on.
Second approach - why layout is incorrect way to place widgets? If I will keep size of each widget as it should be (according to sectionSize()) then layout will do all placement work. In your suggestion - I will have to manually calculate all this what layout does. Layout is so much inefficient?
PS. Similar thing I would like to do with vertical header - this time to add four horizontally aligned widgets.
Re: Subclassing QHeaderView
Quote:
Originally Posted by
T4ng10r
Second approach - why layout is incorrect way to place widgets?
Because then the layout takes control of widget sizes and position. What happens if you start scrolling your view horizontally or resize sections? How will you hide a portion of a widget or how will you move those widgets aroung, especially if the last section of the header has the Stretch resize mode? You'll have more work this way than when positioning widgets manually.
Re: Subclassing QHeaderView
Thanks.
Are there any examples or tutorials with subclassed QHeaderView?
Re: Subclassing QHeaderView
No, I haven't seen any. But it's not difficult, I've done it myself once or twice.