Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Minimum Size For qtreewidget columns
Forum Updated to NodeBB v4.3 + New Features

Minimum Size For qtreewidget columns

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 3.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Abhi_Varma
    wrote on 17 Jan 2022, 10:33 last edited by
    #1

    Re: Minimum size for QTableWidget collums/multiple resize modes?

    Facing similar issue as the above mentioned topic. But need help with just setting the minimum/default width to the column so that when table is created the column size should be fixed and when user tries to reduce size of column it cannot be reduced beyond the fixed size. I couldn't find any solutions for this. Any idea how this can be resolved.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 17 Jan 2022, 20:06 last edited by
      #2

      Hi,

      Looks like you want to fix the sections size in the horizontal QHeaderView for your QTreeWidget.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      A 1 Reply Last reply 19 Jan 2022, 08:21
      0
      • S SGaist
        17 Jan 2022, 20:06

        Hi,

        Looks like you want to fix the sections size in the horizontal QHeaderView for your QTreeWidget.

        A Offline
        A Offline
        Abhi_Varma
        wrote on 19 Jan 2022, 08:21 last edited by
        #3

        @SGaist Hi
        I just want to change the minimum width of only one section in the header. I don't see a direct method in header class. I want something similar to setMinimumSectionSize(int) but it needs to take 2 arguments (Index, Width) so that it will set the minimum width to the given index. Is there a way to do this?

        J 1 Reply Last reply 19 Jan 2022, 09:09
        0
        • A Abhi_Varma
          19 Jan 2022, 08:21

          @SGaist Hi
          I just want to change the minimum width of only one section in the header. I don't see a direct method in header class. I want something similar to setMinimumSectionSize(int) but it needs to take 2 arguments (Index, Width) so that it will set the minimum width to the given index. Is there a way to do this?

          J Offline
          J Offline
          JonB
          wrote on 19 Jan 2022, 09:09 last edited by JonB
          #4

          @Abhi_Varma
          I don't think there is a call for a minimum section size for just one column/row.

          There are several ways to achieve what you want. But I think in the case of a QTreeWidget (as opposed to a QTreeView) the most obviously-supported way would be QTreeWidget::setHeaderItem(QTreeWidgetItem *item) and in the item QTreeWidgetItem::setSizeHint(int column, const QSize &size). You would have to try. There may be better/simpler ways, but that's my first thought.

          A 1 Reply Last reply 21 Jan 2022, 06:24
          0
          • J JonB
            19 Jan 2022, 09:09

            @Abhi_Varma
            I don't think there is a call for a minimum section size for just one column/row.

            There are several ways to achieve what you want. But I think in the case of a QTreeWidget (as opposed to a QTreeView) the most obviously-supported way would be QTreeWidget::setHeaderItem(QTreeWidgetItem *item) and in the item QTreeWidgetItem::setSizeHint(int column, const QSize &size). You would have to try. There may be better/simpler ways, but that's my first thought.

            A Offline
            A Offline
            Abhi_Varma
            wrote on 21 Jan 2022, 06:24 last edited by
            #5

            @JonB This was not working. When we setMinimumWidth it restricts the user from reducing the size of column beyond that width. I want to restrict user from reducing the size of 1 column beyond the custom set minimum width of that column. Your solution was not restricting me from reducing the size of column.

            For Example, Say I have 3 Columns. I setMinimumWidth(20) for all the sections of header, For my first column it should have a width of 80 and restrict user from reducing size of column but allow increasing column size.

            I understand there are no direct ways to achieve this but any workaround will help.

            1 Reply Last reply
            0
            • A Offline
              A Offline
              Abhi_Varma
              wrote on 21 Jan 2022, 16:18 last edited by
              #6

              @JonB , @SGaist I found a bad hack, I know for sure this is not the correct way to program this feature but what I have done is whenever we resize a column a SIGNAL( sectionResized(index, oldSize, newSize) ) is emitted by header view class. I connected a SLOT (OnSectionResized(index, oldSize, newSize) )

              void OnSectionResized(int index, int oldSize, int newSize)
              {
                      Q_UNUSED(oldSize);
                      if( index == FIRST_COLUMN_INDEX && newSize < FIRST_COLUMN_MIN_WIDTH )
                      {
                              pTreeView->setColumnWidth(index, FIRST_COLUMN_MIN_WIDTH );
                      }
              }
              

              Any other workaround is much appreciated.

              1 Reply Last reply
              0

              1/6

              17 Jan 2022, 10:33

              • Login

              • Login or register to search.
              1 out of 6
              • First post
                1/6
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved