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. [SOLVED] QTableView - showing vertical scrollbar
Forum Update on Monday, May 27th 2025

[SOLVED] QTableView - showing vertical scrollbar

Scheduled Pinned Locked Moved General and Desktop
8 Posts 2 Posters 4.2k Views
  • 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.
  • M Offline
    M Offline
    maximus
    wrote on 8 Oct 2014, 23:30 last edited by
    #1

    Hi guys,

    I have this custom QTableView:
    https://www.dropbox.com/s/8joavwkefrlzumn/workoutAsExpected.png?dl=0

    When I click some cell in the QTableView, I got this kind of custom editor pop out:
    https://www.dropbox.com/s/lxw6n1dwscpep3y/popUpOk.png?dl=0
    This work really well, but if I try to edit the last row I get this :
    https://www.dropbox.com/s/bwttpdpb6m6yjm8/lastLineEditorProblem.png?dl=0

    So the problem is that part of the editor is shown outside of the range of the QTableView, the custom editor height is double the size of a row, that may explain why. I tried to re-implement some function in QTableView like rowHeight(int row) to return a fixed size, but I still get the problem. Does anyone knows how the vertical scrollbar algorithm auto-detection to show or not (scrollbarAsNeeded) works? I could reimplement it and force to show the scrollbar when an editor is active or maybe some kind of other hacks, suggestion welcome!

    Thanks in advance!


    Free Indoor Cycling Software - https://maximumtrainer.com

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 9 Oct 2014, 11:33 last edited by
      #2

      Hi,

      Are you placing the editor by hand ? If so you could move it so it doesn't go beyond the bottom your cell

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

      1 Reply Last reply
      0
      • M Offline
        M Offline
        maximus
        wrote on 9 Oct 2014, 12:53 last edited by
        #3

        Hey SGaist,

        I'm using an QStyledItemDelegate to create the editor.

        A different editor is created depending on the column:

        @QWidget *IntervalDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const

        {
        /// Cadence
        else if (index.column() == 3 ) {
        CadenceEditor *editor = new CadenceEditor(parent);
        connect (editor, SIGNAL(endEdit()), this, SLOT(closeWidgetEditor()) );
        return editor;
        }
        ...
        }@

        The editor have fixed size :

        @void IntervalDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index ) const {
        editor->setGeometry(option.rect);
        /// Cadence
        else if (index.column() == 3) {
        editor->setGeometry(option.rect.x(), option.rect.y(), 350, 90);
        }
        }

        QSize IntervalDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
        {
        return QStyledItemDelegate::sizeHint(option, index);
        }
        @

        I would prefer the editor to pop up where it is actually poping (on the good cell) and instead maybe force an empty line in the QTableView (at the end) so that the editor never get shown outside it. Thinking of work-around on how to do that..
        Thanks!


        Free Indoor Cycling Software - https://maximumtrainer.com

        1 Reply Last reply
        0
        • M Offline
          M Offline
          maximus
          wrote on 9 Oct 2014, 23:31 last edited by
          #4

          I think i'm running out of idea to fix this bug.. any advice appreciated! Will pay dogecoin as usual :P


          Free Indoor Cycling Software - https://maximumtrainer.com

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 13 Oct 2014, 20:32 last edited by
            #5

            Personally, I would just align the editor on the bottom of the last cell if it can't be fully drawn. That's what you get for e.g. context menu

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

            1 Reply Last reply
            0
            • M Offline
              M Offline
              maximus
              wrote on 13 Oct 2014, 22:53 last edited by
              #6

              What happen when I open the context menu on the last row here : The context menu is drawn partially inside the QTableView and the rest that doesn't fit is drawn outside of it.
              That would be a perfect solution for my problem.

              Not sure how to draw an editor partially inside the QTableView and the rest outside, maybe I can try not passing the QTableView as parent to my editor, and setting the position manually somehow? Will check that option a little.
              Thanks!


              Free Indoor Cycling Software - https://maximumtrainer.com

              1 Reply Last reply
              0
              • M Offline
                M Offline
                maximus
                wrote on 14 Oct 2014, 00:50 last edited by
                #7

                Solved! Thanks Sgaist for getting my mind to start working again!
                Just needed a line in the delegate updateEditorGeometry function.

                In action:
                https://www.dropbox.com/s/odz9k4lnxlu8wwy/popUpEditor.png?dl=0

                Code :
                @void IntervalDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index ) const {

                editor->setGeometry(option.rect);
                
                /// Power
                if (index.column() == 2) {
                    editor->setWindowFlags(Qt::Popup);
                    editor->setGeometry(option.rect.x(), option.rect.y(), 700, 90);
                    editor->move(editor->parentWidget()->mapToGlobal(option.rect.topLeft()));
                }@
                

                Free Indoor Cycling Software - https://maximumtrainer.com

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 14 Oct 2014, 21:56 last edited by
                  #8

                  You're welcome !

                  That's also an interesting alternative :)

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

                  1 Reply Last reply
                  0

                  1/8

                  8 Oct 2014, 23:30

                  • Login

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