Results 1 to 8 of 8

Thread: Subclassing QHeaderView

  1. #1
    Join Date
    Feb 2007
    Location
    Wroclaw, Poland
    Posts
    72
    Thanks
    6
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Subclassing QHeaderView

    Hi,
    I want to put QCheckBox and QComboBox in each column header.
    Previously I was creating entire new View (based on QGridLayout) to achieve this.
    Currently I'm subclassing QHeaderView, then add layout in constructor with parent to viewport(). In layout place widget and small layout for each column. But this is ... complicated. Is there any other easier solution?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Subclassing QHeaderView

    What is the layout for?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Feb 2007
    Location
    Wroclaw, Poland
    Posts
    72
    Thanks
    6
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default 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.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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().
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. The following user says thank you to wysota for this useful post:

    T4ng10r (20th August 2011)

  6. #5
    Join Date
    Feb 2007
    Location
    Wroclaw, Poland
    Posts
    72
    Thanks
    6
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default 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.

  7. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Subclassing QHeaderView

    Quote Originally Posted by T4ng10r View Post
    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #7
    Join Date
    Feb 2007
    Location
    Wroclaw, Poland
    Posts
    72
    Thanks
    6
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Subclassing QHeaderView

    Thanks.
    Are there any examples or tutorials with subclassed QHeaderView?

  9. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Subclassing QHeaderView

    No, I haven't seen any. But it's not difficult, I've done it myself once or twice.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. QHeaderView with QMenu
    By baray98 in forum Qt Programming
    Replies: 1
    Last Post: 11th June 2010, 17:07
  2. QHeaderView
    By waynew in forum Qt Programming
    Replies: 2
    Last Post: 25th December 2009, 20:42
  3. QHeaderView
    By gyre in forum Qt Tools
    Replies: 1
    Last Post: 25th September 2007, 16:35
  4. QHeaderView as a banner
    By mclark in forum Qt Programming
    Replies: 1
    Last Post: 21st March 2007, 19:28
  5. subclassing QHeaderView
    By chemstar in forum Qt Programming
    Replies: 7
    Last Post: 22nd May 2006, 12:34

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.