Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Drawing custom Widgets
Qt 6.11 is out! See what's new in the release blog

Drawing custom Widgets

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
1 Posts 1 Posters 525 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.
  • PemdasP Offline
    PemdasP Offline
    Pemdas
    wrote on last edited by
    #1

    I am looking for some advice on how to implement a list view with custom content in each row. I have implemented exactly what I want using QLIstWidget, but the QListwidget "eats" any widgets that I pass to it and I don't want that behavior. Also, this list could be "long" and I don't want to allocate 100s of widgets.

    The easiest why to describe what I am trying to accomplish is to look at my delegate paint function. This is just a simple example for the sake of this question.

    void CustomItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
    const QModelIndex &index) const
    {

    qDebug() << "Painting something" << endl;
    if(index.data().canConvert<CustomModelItem>())
    {
        CustomModellItem item = qvariant_cast<CustmomModelItem>(index.data());
        QApplication::style()->drawControl(QStyle::CE_ItemViewItem, &option, painter, item.getItem());
    }
    else
    {
        qDebug() << "Delegate...something broken 2" << endl;
        QStyledItemDelegate::paint(painter, option, index);
    
    }
    

    }
    CustomModelItem is nothing more than a wrapper structure that holds a pointer a custom widget.

    I realize that I could just manual draw the control since it is nothing more than a collection of labels and icons, but I want to draw the item with properties that are defined in a stylesheet. Any advice would be appreciated.

    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