Search code examples
c++qtqlistwidgetqlistwidgetitem

Blog like QListWidget in Qt


How to make in Qt item list like QListWidget, but multiple rows, multiple images, buttons like html text link, and text decoration (bold/italic/etc).

enter image description here

Help me if you know at least one of these options.

Thanks.


Solution

  • You can customize QListWidget as you like. Please study this thread:

    http://www.qtcentre.org/threads/27777-Customize-QListWidgetItem-how-to

    It has all the information you need. The idea is that you need to set custom delegate using the function setItemDelegate of your QListWidget.

    class ListDelegate : public QAbstractItemDelegate
    {
        public:
            ListDelegate(QObject *parent = 0);
    
            void paint ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const;
            QSize sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const;
    
            virtual ~ListDelegate();
    
    };
    

    In the paint() function you may paint all the text/images as you need.