Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

columnWidth glitch



  • If I call QTablewidget::columnWidth in my constructor before showing the dialog, then my hidden columns will have 0 width when I unhide them during runtime.

    When I simply leave out the columnWidth call they will show with correct size.

    It doesn't matter if columnWidth was called before or after initially hiding the column. (I thought it might have been set to 0 because of it being hidden). The width before hiding is 150.

    Do you think this is worth a ticket?


  • Lifetime Qt Champion

    Hi,

    Technically, trying to get the size of any GUI component in its constructor doesn't make sense as they have no "physical" representation.

    That said, why are you trying to retrieve the width of columns you are hiding ?



  • No I am retrieving the width of columns after they get shown in order to fix a bug where they end up with 0 width despite the use of minimum section size:

    setColumnHidden(col, vis);
    
    if (vis && isVisible() && columnWidth(col) <= horizontalHeader()->minimumSectionSize())
    {
        setColumnWidth(col, horizontalHeader()->minimumSectionSize());
    }
    

    Probably another bug for the bug tracker unless you know the reason for this to happen.
    My assumption is that this has to do with restoring window states.


  • Lifetime Qt Champion

    Can you provide a minimal compilable example that shows that behaviour ?



  • I can try. But it will probably take some time.

    I can probably only give you code for the columnWidth glitch, since the other bug has been quite rare


  • Lifetime Qt Champion

    I don't think that you will get a section size smaller than the minimum section size with 5.11 and higher... :)



  • why do you think that? @Christian-Ehrlicher

    @SGaist I don't think I can reproduce this without my source code. But it's fine. I found a workaround by only doing the size fix on visible Tables. (aka after showing the main window)


  • Lifetime Qt Champion



  • Hmm that could be it. I should target 5.11 and see if it fixes this issue. I also use setStretchLastSection(true) and resizeColumnsToContents at some point. It wouldn't surprise me if this caused the columns to misbehave.


  • Lifetime Qt Champion

    If you find issues with 5.11 please provide a minimal, compilable example so we can fix it.



  • After reviewing it I am even more confused.
    My initial statement suggests that simply the call caused the behaviour:
    When I simply leave out the columnWidth call they will show with correct size. It doesn't matter if columnWidth was called before or after initially hiding the column.

    But I can't reproduce it anymore and I get the feeling that I missed a detail.
    My current tests indicate that I might have actually changed the width of hidden items by mistake a some point.
    That width turns out to be zero.

    So my latest fix is to simply ignore hidden items regarding any columnWidth call.

    I'll mark this topic as resolved for now.
    Although I am still certain that the behaviour happened like I said at some point at least. (simply added a columnWidth(col); somewhere)
    If I ever manage to find it again I will let you know.



  • I found another one. It definitely happens whenever I have sorting enabled while a column is hidden.
    Sorting by clicking a header and then showing the columns again will result in narrow columns.



  • as a workaround i now use my own sorting function that unhides all columns before sorting and hides them again afterwards.

    Do you think there is an option to achieve that by default?


Log in to reply