Results 1 to 3 of 3

Thread: QTableWidget -- how to handle column resizing? (QHeaderView)

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2007
    Location
    Toruń, POLAND
    Posts
    24
    Thanks
    7
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default QTableWidget -- how to handle column resizing? (QHeaderView)

    Hello,

    QTableWidget, 2 columns. When the user resizes the window I also resize the columns.

    User should be able to resize columns manually by resizing horizontal header, but here lies the problem. QTableWidget gets the resize event on resizing horizontal header columns! So now I don't know what was the reason of the resizeEvent.

    I tried to disconnect original QHeaderView signal when resizing and connect to my own slot, but in the code I have to call setColumnWidth and this method is resizing column via header and header sends the signal I just get, so now it is recurrent loop.
    I could in theory only process even calls, and ignore odd ones, but this solution is ugly (I didn't even try it).

    So, my question is -- how to tell in resizeEvent where from this even came OR how to handle resize signal from QHeaderView without falling in infinitive loop?

    Thanks in advance for tips, ideas, help :-)

    have a nice evening, bye

  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: QTableWidget -- how to handle column resizing? (QHeaderView)

    You can install an event filter on the header view and mark the event as handled (by returning true from the eventFilter() method) so that the table widget doesn't receive them.

    I suspect it'd be easier to subclass the table widget and reimplement its resizeEvent and update the columns there after the header gets adjusted by the original resizeEvent (you have to call the base class implementation yourself of course).

    BTW. Have you tried to simply set the resizeMode of the second column in the header to Stretch?
    Last edited by wysota; 14th August 2007 at 13:44.

  3. #3
    Join Date
    Apr 2007
    Location
    Toruń, POLAND
    Posts
    24
    Thanks
    7
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QTableWidget -- how to handle column resizing? (QHeaderView)

    Thank you for your answer. In reverse order :-)

    Quote Originally Posted by wysota View Post
    BTW. Have you tried to simply set the resizeMode of the second column in the header to Stretch?
    Yes, but it is not enough -- if I resize the whole table x2, the first column will not get 50% of the resize, all extra width will go to the second. And my goal is to make resizing (of entire table) fair for all columns.

    Quote Originally Posted by wysota View Post
    I suspect it'd be easier to subclass the table widget and reimplement its resizeEvent and update the columns there after the header gets adjusted by the original resizeEvent (you have to call the base class implementation yourself of course).
    I already did this, but as I said before -- I don't know if the entire table is resizing or just one column -- everything is pushed into resizeEvent.

    Quote Originally Posted by wysota View Post
    You can install an event filter on the header view and mark the event as handled (by returning true from the eventFilter() method) so that the table widget doesn't receive them.
    Thank you -- I just tried it, but it does not work. Why? The design of header<->table interaction is a bit bizarre

    column header is being resized -> it sends a signal -> signal is caught by table -> table says update columns -> method updating columns calls in some place resizeEvent of the table

    So when I installed filter I got a lot of events from the header but not this one when the header column was resized.

    have a nice day, bye

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.