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. QTableWidget: prevent collumns to be cropped when resized
Forum Updated to NodeBB v4.3 + New Features

QTableWidget: prevent collumns to be cropped when resized

Scheduled Pinned Locked Moved General and Desktop
7 Posts 2 Posters 3.3k 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.
  • J Offline
    J Offline
    JulienMaille
    wrote on last edited by
    #1

    Dear All,
    I'm trying to find out how to get proper column resizing when the parent (a QDockWidget) is resized itself.
    Here is what I currently get:
    !http://i.imgur.com/poSxkRg.png! !http://i.imgur.com/H03LQLf.png!

    I tried all the sizePolicies on both the QTableWidget and its layout, but I always get the same behavior.
    Any help will be much appreciated!

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      What would you want it to do?

      1 Reply Last reply
      0
      • J Offline
        J Offline
        JulienMaille
        wrote on last edited by
        #3

        I would like it to internally keep a minimumWidth reflecting current data.
        That would forbid the user to resize the width below the value where the cropping occurs.
        That is the standard behavior of other QWidgets. If you add a QLabel in a QDockWidget, you cannot crop it when resizing: here in that snapshot this is the minimum width the user can set:
        !http://i.imgur.com/70sjPwi.png!

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          I think I'd subclass QTableWidget, and reimplement the sizeHint. In your reimplementation, you can use QTabelView::sizeHintForColumn to get the optimal width for each of your columns. Sum them, and if needed, add the width of the scroll bar.

          1 Reply Last reply
          0
          • J Offline
            J Offline
            JulienMaille
            wrote on last edited by
            #5

            Subclassing just for this reason is a bit annoying.

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #6

              Then set minimumSize with the results of the same calculation...

              1 Reply Last reply
              0
              • J Offline
                J Offline
                JulienMaille
                wrote on last edited by
                #7

                OK, I took the opportunity to learn how the "promote to" function (in Designer) works.

                I came up with that but it does not work. minimumSizeHint is not called when resizing ...
                EDIT: I had to reimplement resizeEvent to get it working. Not sure if it's the proper way to do it.

                @class MyTableWidget : public QTableWidget
                {
                public:
                MyTableWidget(QWidget* parent = NULL) : QTableWidget(parent) {}

                QSize minimumSizeHint() const
                {
                    QSize size(QTableWidget::sizeHint());
                
                    int width = verticalHeader()->isVisible() ? verticalHeader()->width() : 0;
                
                    // Sum over all the columns width
                    for( int c=0; c<columnCount(); ++c )
                        width += isColumnHidden(c) ? 0 : sizeHintForColumn(c);
                
                    // Handle vertical scroll bar
                    width += verticalScrollBar()->isVisible() ? verticalScrollBar()->width() : 0;
                
                    size.setWidth(width);
                    return size;
                }
                
                QSize sizeHint() const
                {
                    return minimumSizeHint();
                }
                

                protected:
                void resizeEvent(QResizeEvent* e)
                {
                setMinimumSize(minimumSizeHint());
                QTableWidget::resizeEvent(e);
                }
                };@

                1 Reply Last reply
                0

                • Login

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