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. Custom item delegate sizeHint() does not set item height in QTreeView
Forum Updated to NodeBB v4.3 + New Features

Custom item delegate sizeHint() does not set item height in QTreeView

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 895 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.
  • michalosM Offline
    michalosM Offline
    michalos
    wrote on last edited by VRonin
    #1

    Hi,
    Does anyone know what I am doing wrong?
    I've implemented the sizeHing() function in my custom delegate, as I found in few posts on this and other forums, and still I cannot set the items height.
    It seems like QStyleOptionViewItem doesn't have the correct width for the item.
    I have word wraping implemented in column nr 2, and when I open my app not all text is visible (some is draged down, like under the item in the next row).

    QSize MyItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
    {
        if(index.column() == 2){
    
        QStyleOptionViewItem options = option;
    
        initStyleOption(&options, index);
    
        QTextDocument textDoc;  
        QString contactName = index.data(Qt::DisplayRole).toString();
        QString contactPhone = index.data(Qt::UserRole).toString();
        QString contactInfo = index.data(Qt::UserRole+1).toString();
    
        QTextCursor textCursor(&textDoc);
        QImage stanPoint = index.data(Qt::UserRole+2).value<QImage>();/*(contactStan.toImage());*/
    
        bool wczytajfote = !stanPoint.isNull();
    
        textCursor.insertHtml(contactName);
        if(wczytajfote){
        textCursor.movePosition(QTextCursor::EndOfLine, QTextCursor::MoveAnchor);
        textCursor.insertImage(stanPoint);
        textCursor.movePosition(QTextCursor::End, QTextCursor::MoveAnchor);
        }
        textCursor.insertHtml(contactPhone);
        textCursor.insertHtml(contactInfo);
    
            textDoc.setTextWidth(options.rect.width());
    
        return QSize(textDoc.idealWidth(), textDoc.size().height());
    
        } else return QSize(30,30);
    }
    

    If I need to provide more code, please let me know.

    The app GUI looks like this : Click for the link to the image

    I don't know if it's important, but I have this columns header set to resize to fit the free space of the tree view (all other columns are set to static size of QSize(30, 30)

    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