Results 1 to 3 of 3

Thread: Custom QWidget with more than 2 controls including buttons inside QListView

  1. #1
    Join Date
    Apr 2011
    Posts
    61
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Custom QWidget with more than 2 controls including buttons inside QListView

    I want to put a QWidget inside QListView, tried with setItemWidget and not worked, but now I'm using QListView in a new project and need to do this.

    It's a download list.

    How can I do this ?

  2. #2
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Custom QWidget with more than 2 controls including buttons inside QListView

    QListView is a different thing from QListWidget which i assume you want to use because this one has setItemWidget.

  3. #3
    Join Date
    Apr 2011
    Posts
    61
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Custom QWidget with more than 2 controls including buttons inside QListView

    I've used the Widget before, but not worked, now I've started another project using QListView and want to do this using it. I'm trying to do this with delegates.

    How I can calculate the sizes ?

    I'm using this code but I don't think it's the best way:

    Qt Code:
    1. void DownloadItemDelegate::paint(
    2. QPainter* painter,
    3. const QStyleOptionViewItem& option,
    4. const QModelIndex& index) const
    5. {
    6. painter->drawText(option.rect.x() + 2, option.rect.y() + option.fontMetrics.height(), index.data(Qt::DisplayRole).toString());
    7.  
    8. sop.state = QStyle::State_Enabled;
    9. sop.rect = option.rect.adjusted(2, option.fontMetrics.boundingRect(index.data(Qt::DisplayRole).toString()).height() + option.fontMetrics.height() / 2, -2, 0);
    10. sop.fontMetrics = option.fontMetrics;
    11. sop.minimum = 0;
    12. sop.maximum = 100;
    13. sop.progress = 50;
    14. sop.orientation = Qt::Horizontal;
    15. sop.textVisible = false;
    16.  
    17. QApplication::style()->drawControl(QStyle::CE_ProgressBar, &sop, painter);
    18. }
    19.  
    20. QSize DownloadItemDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
    21. {
    22. if (option.rect.width() == 0 || option.rect.height() == 0) return QSize();
    23.  
    24. QSize size = option.rect.size();
    25. size.setHeight(option.fontMetrics.boundingRect(index.data(Qt::DisplayRole).toString()).height());
    26. size.setHeight(size.height() + 20);
    27.  
    28. qDebug() << size.width() << "x" << size.height();
    29. return size;
    30. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by rsilva; 16th May 2011 at 00:24.

Similar Threads

  1. styling controls inside QTreeView
    By mentalmushroom in forum Qt Programming
    Replies: 2
    Last Post: 27th May 2011, 18:25
  2. Replies: 2
    Last Post: 3rd April 2010, 15:18
  3. Custom controls when QTreeWidgetItem edited.
    By kubas in forum Qt Programming
    Replies: 3
    Last Post: 4th September 2009, 10:27
  4. Maximum number of controls in QWidget
    By soumyadeep_pan in forum Qt Programming
    Replies: 4
    Last Post: 7th February 2009, 04:53
  5. Custom shaped forms and controls
    By AlbertGoodwill in forum Qt Programming
    Replies: 1
    Last Post: 19th October 2007, 06:35

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.