How to make vertical header of QTableWidget resizable by mouse?



  • I need to make vertical header of QTableWidget resizable by mouse like sections. I also want to make the same reaction for double click. How can I do this?


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    When double clicking a section you'll have sectionDoubleClicked emitted. With that you can trigger a resize on the corresponding section.

    Hope it helps



  • When double clicking a section you'll have sectionDoubleClicked emitted. With that you can trigger a resize on the corresponding section.

    I am talking about behaviour when cursor is under splitter between vertical header column and section column. If left mouse button is pressed and mouse move than resizing is need. Double click - auto resizing.


  • Lifetime Qt Champion

    So that would be sectionHandleDoubleClicked



  • So that would be sectionHandleDoubleClicked

    I am talking about vertical header resizing. Not about sections resizing. And primary problem is resizing by mouse moving when left mouse button is pressed I want to make cursor as resizing cursor when it is under splitter between vertical header and first section. Than if left mouse button is pressed mouse moving resizes vertical header width. I want exactly same behaviour like for sections.


  • Lifetime Qt Champion

    The vertical and horizontal header view follow the same logic. I might misunderstand you, can you show a picture how what you would like to achieve ?



  • Alt text
    I need to make vertical header resizeable by mouse when cursor is between vertical header and first section.


  • Lifetime Qt Champion

    Did you set the ResizeMode ?



  • Did you set the ResizeMode ?

    I'm talking about resizing of vertical header width not about sections. With sections all is well.

    Alt text
    This is what do I need.



  • Hi asmirn
    I think I have a solution regarding your question.

    You have to implement the resize mechanism by yourself as the QTableView / QHeaderView will not support the resizing by itself.

    The way i did:

    First derive a subclass from QHeaderView (e.g. VerticalHeaderView) and override the mousePressEvent / mouseMoveEvent / mouseReleaseEvent, to get the relevant mouseclicks mousemove-positions for the headerview.

    Then if the user clicks the left mouse button in a certain distance to the left VerticalHeaderView border you can start
    resizing the VerticalHeaderView with setFixedWidth(newWidth).
    Do not forget to tell the according QTableView/QTableWidget about the resizing by calling updateGeometries() for the QTableView/QTableWidget.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.