[SOLVED] QTableView - showing vertical scrollbar



  • 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!


  • Lifetime Qt Champion

    Hi,

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



  • 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!



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


  • Lifetime Qt Champion

    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



  • 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!



  • 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()));
    }@

  • Lifetime Qt Champion

    You're welcome !

    That's also an interesting alternative :)


Log in to reply
 

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