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. sizeHintForColumn not returning size including icon size

sizeHintForColumn not returning size including icon size

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 162 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.
  • K Offline
    K Offline
    Krpadia123
    wrote on last edited by
    #1

    Hi,
    I am trying to add item that have icon and label to QlistWidget, and I want to resize my item to its content that where I am using sizeHintForColumn to adjust, but its just returning size of text hence my text is getting cropped.

    Code:

    void QTListWidget::addItems()
    {
        for(int i = 0 ; i < 10 ; i++)
        {
            QLabel* pLabel = new QLabel(QString::fromStdString("labelText") + QString::fromStdString(getString()));
            QListWidgetItem* item = new QListWidgetItem();
            item->setTextAlignment(Qt::AlignLeft | Qt::AlignVCenter);
    
    
            //addIcon
            item->setIcon(QIcon("success-16x16.png"));
            
            //size item to widget current max widget
            item->setSizeHint(QSize(this->sizeHintForColumn(0) + 1, 20));
    
            addItem(item);
            setItemWidget(item, pLabel);
        }
    }
    

    Result:
    05c15c8c-7829-495f-981b-a17b76dd0ec6-Screenshot (125).png

    Is there any way we can get size and adjust it to fit the contents?

    Any help is very much 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