Skip to content
  • 0 Votes
    5 Posts
    392 Views
    J

    @JonB I'm still wondering if the right approach would be to use a QItemViewDelegate subclass. I need custom painting of the rows when they come into view based on a global UI setting (colored or normal display) and the content of one of the cells in the row (the threadID).

    The Star Delegate example seems to indicate that custom cell painting is done via these view delegates.

    I thought that the way these delegates are supposed to work is that they get called for painting or editing on demand (i.e. when their cells are visible via the scrollbars or double clicked for editing).

    This way the change from normal to colored rows would refresh the visible view (I don't really need to store the background with each item in the table as it is just for visibility purposes.

  • 0 Votes
    3 Posts
    557 Views
    GrecKoG

    Use a SequentialAnimation and put a PauseAnimation in it first, with a duration depending on the index of the delegate.

  • 0 Votes
    10 Posts
    2k Views
    jeanmilostJ

    Thanks to all for the replies.

    I finally resolved the issue by replacing the TableView by a ListView and rewriting the columns handling manually. As the ListView draws the whole item content once, all the above mentioned issues are resolved at the same time.

    However very interesting concepts were presented here, and they may help me for other similar situations in the future. Once again, thank you very much to took the time to help me and reply to my questions.

  • 0 Votes
    6 Posts
    3k Views
    N

    This is what I've done right now.
    Using the same code for painting and widget, I'm able to use a custom widget as usual; moreover, for listview I'm able to render the same widget correctly (because calling render method of widget, the widget is able to read .qss stylesheet)

    Here is the example:

    this is a single widget
    0_1562332451778_widget.png

    and this is the rendered widget inside the listview
    0_1562332527764_listview-render.png

    in listview, as you can see, I'm able to render widget correctly and, in case of focus, I can change focus style using a custom property

    this is the code:

    void AlertItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const { QVariant data = index.data(); if (data.canConvert<Error>()) { auto&& styleOption = QStyleOptionViewItem(option); ErrorItemWidget widget; if (styleOption.state & QStyle::State_HasFocus) widget.setProperty("Test", true); // <-- custom focus property else widget.setProperty("Test", QVariant::Invalid); // <-- remove property for normal state widget.resize(option.rect.width(), option.rect.height()); widget.setError(qvariant_cast<Error>(data)); painter->save(); painter->translate(option.rect.topLeft()); widget.render(painter); painter->restore(); } else { QStyledItemDelegate::paint(painter, option, index); } }

    The drawback of this solution is that I need to create a widget for each model item (however, I've render 2000 elements and I don't see any performance hit)
    The other drawback is that the height of each item is hardly code inside size-hint method, that is:

    QSize AlertItemDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const { int width = option.rect.width(); int height = 48; // <--- if I can get this from stylesheet, I'll be happy :) return QSize(width, height); }

    The good thing is that I can change widget stylesheet using .qss file; inside C++ code there isn't any style detail.

    Any suggestion to get height value from stylesheet?

    Thanks all!
    Nicola

  • 0 Votes
    1 Posts
    322 Views
    No one has replied
  • 0 Votes
    2 Posts
    2k Views
    T

    By adding the line "property alias mouser: mouseArea" to the TreeView.qml of Qt, I can implement mouser.onPressed: {...} inside my TreeView code.
    This way both the selection and drag&drop work, but I actually don't like the idea of modifying Qt code.

    No one out there with an approach how to solve this a bit cleaner?

  • 0 Votes
    4 Posts
    7k Views
    kshegunovK

    @Joel-Bodenmann

    Sometimes it's hard to track down inherited members from the base page of the class. When you're in doubt you can go to the "List of all members, including inherited members" page. ;)

  • 0 Votes
    8 Posts
    5k Views
    Joel BodenmannJ

    At the end, @SGaist pointed me to this implementation of a checkbox item delegate which works very well.