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. Thumbnails using List Widget
Forum Update on Monday, May 27th 2025

Thumbnails using List Widget

Scheduled Pinned Locked Moved Solved General and Desktop
17 Posts 4 Posters 3.5k 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.
  • A Offline
    A Offline
    amarism
    wrote on 12 Jun 2018, 06:43 last edited by
    #1

    I am making a Thumbnail using list widget. That store the bundle of an image. Now I want to display the image with a number just like If I add 5 images they display the number like 1 to 5.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 12 Jun 2018, 06:58 last edited by VRonin 6 Dec 2018, 08:56
      #2

      hi
      Cant you just use the normal text for that ?
      new QListWidgetItem(QIcon(":/xxx"), "the number")

      or what is the question exactly ?

      A 1 Reply Last reply 12 Jun 2018, 07:04
      2
      • M mrjj
        12 Jun 2018, 06:58

        hi
        Cant you just use the normal text for that ?
        new QListWidgetItem(QIcon(":/xxx"), "the number")

        or what is the question exactly ?

        A Offline
        A Offline
        amarism
        wrote on 12 Jun 2018, 07:04 last edited by VRonin 6 Dec 2018, 08:56
        #3

        @mrjj I am using this code for the thumbnail

        QPalette p;
        	this->ui->m_ThumblistWidget->setViewMode(QListWidget::IconMode);
        	this->ui->m_ThumblistWidget->setIconSize(QSize(100, 100));
        	this->ui->m_ThumblistWidget->setResizeMode(QListWidget::Adjust);
        	p.setBrush(QPalette::Window, Qt::transparent);
        	this->ui->m_ThumblistWidget->setPalette(p);
        	View>GenerateThumbList(this->ui->m_ThumblistWidget);
        

        Also i need to dynamically assign the number in the image

        M 1 Reply Last reply 12 Jun 2018, 07:07
        0
        • A amarism
          12 Jun 2018, 07:04

          @mrjj I am using this code for the thumbnail

          QPalette p;
          	this->ui->m_ThumblistWidget->setViewMode(QListWidget::IconMode);
          	this->ui->m_ThumblistWidget->setIconSize(QSize(100, 100));
          	this->ui->m_ThumblistWidget->setResizeMode(QListWidget::Adjust);
          	p.setBrush(QPalette::Window, Qt::transparent);
          	this->ui->m_ThumblistWidget->setPalette(p);
          	View>GenerateThumbList(this->ui->m_ThumblistWidget);
          

          Also i need to dynamically assign the number in the image

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 12 Jun 2018, 07:07 last edited by
          #4

          @amarism

          on the full image or what you ?
          or under each item in the widgetlist ?

          A 1 Reply Last reply 12 Jun 2018, 07:21
          0
          • M mrjj
            12 Jun 2018, 07:07

            @amarism

            on the full image or what you ?
            or under each item in the widgetlist ?

            A Offline
            A Offline
            amarism
            wrote on 12 Jun 2018, 07:21 last edited by
            #5

            @mrjjI am attaching the image reference
            0_1528787927301_thumbnail.png

            This one is my thumbnail of list widget containing the 6 image but initially numbering is not there but I want to display the numbering in place one red mark is or bottom of every image like (1,2,3......)

            M 1 Reply Last reply 12 Jun 2018, 07:23
            0
            • A amarism
              12 Jun 2018, 07:21

              @mrjjI am attaching the image reference
              0_1528787927301_thumbnail.png

              This one is my thumbnail of list widget containing the 6 image but initially numbering is not there but I want to display the numbering in place one red mark is or bottom of every image like (1,2,3......)

              M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 12 Jun 2018, 07:23 last edited by
              #6

              @amarism
              if you insert number as text when you create the
              QListWidgetItem in GenerateThumbList
              then it will show under each in list.

              you can use
              QString::number() to convert from int to number.

              1 Reply Last reply
              0
              • V Offline
                V Offline
                VRonin
                wrote on 12 Jun 2018, 08:56 last edited by
                #7

                Can you show us the content of GenerateThumbList?

                "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                ~Napoleon Bonaparte

                On a crusade to banish setIndexWidget() from the holy land of Qt

                A 1 Reply Last reply 12 Jun 2018, 09:37
                0
                • V VRonin
                  12 Jun 2018, 08:56

                  Can you show us the content of GenerateThumbList?

                  A Offline
                  A Offline
                  amarism
                  wrote on 12 Jun 2018, 09:37 last edited by
                  #8

                  @VRonin 0_1528796229765_thumbnail.png

                  V 1 Reply Last reply 12 Jun 2018, 10:04
                  0
                  • A amarism
                    12 Jun 2018, 09:37

                    @VRonin 0_1528796229765_thumbnail.png

                    V Offline
                    V Offline
                    VRonin
                    wrote on 12 Jun 2018, 10:04 last edited by
                    #9

                    @amarism 😓 I meant the code

                    "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                    ~Napoleon Bonaparte

                    On a crusade to banish setIndexWidget() from the holy land of Qt

                    A 1 Reply Last reply 12 Jun 2018, 10:09
                    1
                    • V VRonin
                      12 Jun 2018, 10:04

                      @amarism 😓 I meant the code

                      A Offline
                      A Offline
                      amarism
                      wrote on 12 Jun 2018, 10:09 last edited by
                      #10

                      @VRonin for adding the image inside the listwidget
                      QPalette p;
                      this->ui->m_ThumblistWidget->setViewMode(QListWidget::IconMode);
                      this->ui->m_ThumblistWidget->setIconSize(QSize(100, 100));
                      this->ui->m_ThumblistWidget->setResizeMode(QListWidget::Adjust);
                      p.setBrush(QPalette::Window, Qt::transparent);
                      this->ui->m_ThumblistWidget->setPalette(p);
                      View->GenerateThumbList(this->ui->m_ThumblistWidget);

                      and i try to add numbering to every thumbnail image like this
                      for (int i = 1; i <= this->ui->m_ThumblistWidget->count(); i++) {
                      //this->ui->m_ThumblistWidget->addItem(new QListWidgetItem(NULL, i));
                      }

                      V 1 Reply Last reply 12 Jun 2018, 10:26
                      0
                      • A amarism
                        12 Jun 2018, 10:09

                        @VRonin for adding the image inside the listwidget
                        QPalette p;
                        this->ui->m_ThumblistWidget->setViewMode(QListWidget::IconMode);
                        this->ui->m_ThumblistWidget->setIconSize(QSize(100, 100));
                        this->ui->m_ThumblistWidget->setResizeMode(QListWidget::Adjust);
                        p.setBrush(QPalette::Window, Qt::transparent);
                        this->ui->m_ThumblistWidget->setPalette(p);
                        View->GenerateThumbList(this->ui->m_ThumblistWidget);

                        and i try to add numbering to every thumbnail image like this
                        for (int i = 1; i <= this->ui->m_ThumblistWidget->count(); i++) {
                        //this->ui->m_ThumblistWidget->addItem(new QListWidgetItem(NULL, i));
                        }

                        V Offline
                        V Offline
                        VRonin
                        wrote on 12 Jun 2018, 10:26 last edited by
                        #11

                        What's inside View->GenerateThumbList(this->ui->m_ThumblistWidget);?

                        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                        ~Napoleon Bonaparte

                        On a crusade to banish setIndexWidget() from the holy land of Qt

                        A 1 Reply Last reply 12 Jun 2018, 10:28
                        0
                        • V VRonin
                          12 Jun 2018, 10:26

                          What's inside View->GenerateThumbList(this->ui->m_ThumblistWidget);?

                          A Offline
                          A Offline
                          amarism
                          wrote on 12 Jun 2018, 10:28 last edited by
                          #12

                          @VRonin generating the image in the form of thumbnails in view list

                          V 1 Reply Last reply 12 Jun 2018, 10:31
                          0
                          • A amarism
                            12 Jun 2018, 10:28

                            @VRonin generating the image in the form of thumbnails in view list

                            V Offline
                            V Offline
                            VRonin
                            wrote on 12 Jun 2018, 10:31 last edited by VRonin 6 Dec 2018, 10:36
                            #13

                            generating the image in the form of thumbnails in view list

                            Can you show us the code that does that?


                            A bit in the dark here but this is wrong

                            for (int i = 1; i <= this->ui->m_ThumblistWidget->count(); i++) {
                            //this->ui->m_ThumblistWidget->addItem(new QListWidgetItem(NULL, i));
                            }
                            

                            it overrides what's already there. Try this:

                            for (int i = 0, listCnt = ui->m_ThumblistWidget->count(); i < listCnt ; ++i) {
                            QAbstractItemModel* const model = ui->m_ThumblistWidget->model();
                            model->setData(model->index(i,0),i+1,Qt::EditRole);
                            }
                            

                            "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                            ~Napoleon Bonaparte

                            On a crusade to banish setIndexWidget() from the holy land of Qt

                            A 1 Reply Last reply 12 Jun 2018, 10:41
                            0
                            • V VRonin
                              12 Jun 2018, 10:31

                              generating the image in the form of thumbnails in view list

                              Can you show us the code that does that?


                              A bit in the dark here but this is wrong

                              for (int i = 1; i <= this->ui->m_ThumblistWidget->count(); i++) {
                              //this->ui->m_ThumblistWidget->addItem(new QListWidgetItem(NULL, i));
                              }
                              

                              it overrides what's already there. Try this:

                              for (int i = 0, listCnt = ui->m_ThumblistWidget->count(); i < listCnt ; ++i) {
                              QAbstractItemModel* const model = ui->m_ThumblistWidget->model();
                              model->setData(model->index(i,0),i+1,Qt::EditRole);
                              }
                              
                              A Offline
                              A Offline
                              amarism
                              wrote on 12 Jun 2018, 10:41 last edited by
                              #14

                              @VRonin THIS ONE ALSO NOT WORKING
                              for (int i = 0, listCnt = ui->m_ThumblistWidget->count(); i < listCnt ; ++i) {
                              QAbstractItemModel* const model = ui->m_ThumblistWidget->model();
                              model->setData(model->index(i,0),i+1,Qt::EditRole);
                              }

                              1 Reply Last reply
                              0
                              • KillerSmathK Offline
                                KillerSmathK Offline
                                KillerSmath
                                wrote on 12 Jun 2018, 10:51 last edited by KillerSmath 6 Dec 2018, 10:53
                                #15

                                @amarism

                                If you need to insert a text in the thumbnail, you must to use an QPainter and add a Text on Image

                                Example:

                                #include <QPainter>
                                #include <QImage>
                                #include <QFont>
                                #include <QPen>
                                #include <QString>
                                
                                 ...
                                
                                    QImage img(<image path>); // load image
                                
                                    int number = 15;
                                
                                    QPainter painter(&img); // Pass QImage to Editor
                                    painter.setPen(QPen(Qt::white));
                                    painter.setFont(QFont("Arial", 15, QFont::Bold));
                                
                                    painter.drawText(img.rect(), Qt::AlignCenter, QString::number(number)); // insert number on center of image
                                
                                   // insertImageToTable(img)
                                
                                

                                @Computer Science Student - Brazil
                                Web Developer and Researcher
                                “Sometimes it’s the people no one imagines anything of who do the things that no one can imagine.” - Alan Turing

                                A 1 Reply Last reply 12 Jun 2018, 12:48
                                0
                                • KillerSmathK KillerSmath
                                  12 Jun 2018, 10:51

                                  @amarism

                                  If you need to insert a text in the thumbnail, you must to use an QPainter and add a Text on Image

                                  Example:

                                  #include <QPainter>
                                  #include <QImage>
                                  #include <QFont>
                                  #include <QPen>
                                  #include <QString>
                                  
                                   ...
                                  
                                      QImage img(<image path>); // load image
                                  
                                      int number = 15;
                                  
                                      QPainter painter(&img); // Pass QImage to Editor
                                      painter.setPen(QPen(Qt::white));
                                      painter.setFont(QFont("Arial", 15, QFont::Bold));
                                  
                                      painter.drawText(img.rect(), Qt::AlignCenter, QString::number(number)); // insert number on center of image
                                  
                                     // insertImageToTable(img)
                                  
                                  
                                  A Offline
                                  A Offline
                                  amarism
                                  wrote on 12 Jun 2018, 12:48 last edited by
                                  #16

                                  @KillerSmath In the QImage img(<load image>).
                                  I have the series of image. can I load it

                                  1 Reply Last reply
                                  0
                                  • V Offline
                                    V Offline
                                    VRonin
                                    wrote on 12 Jun 2018, 14:06 last edited by VRonin 6 Dec 2018, 14:20
                                    #17

                                    Ok... let's see if an easy example helps:

                                    #include <QApplication>
                                    #include <QStyledItemDelegate>
                                    #include <QListWidget>
                                    class ImageDelegate : public QStyledItemDelegate{
                                        Q_DISABLE_COPY(ImageDelegate)
                                    public:
                                        explicit ImageDelegate(QObject* parent = Q_NULLPTR)
                                            :QStyledItemDelegate(parent)
                                        {}
                                        void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const Q_DECL_OVERRIDE{
                                            Q_ASSERT(index.isValid());
                                            QStyleOptionViewItem opt = option;
                                            initStyleOption(&opt, index);
                                            QStyle *style = option.widget ? option.widget->style() : QApplication::style();
                                            QPixmap backPix = index.data(Qt::DecorationRole).value<QPixmap>();
                                            if(!backPix.isNull())
                                                style->drawItemPixmap(painter,option.rect,Qt::AlignCenter,backPix.scaled(option.rect.size()));
                                            style->drawItemText(painter,option.rect,Qt::AlignBottom | Qt::AlignRight,option.palette,option.state & QStyle::State_Enabled,index.data(Qt::EditRole).toString());
                                        }
                                    };
                                    
                                    int main(int argc, char *argv[])
                                    {
                                        QApplication application(argc, argv);
                                        QListWidget wid;
                                        wid.setItemDelegate(new ImageDelegate(&wid));
                                        QAbstractItemModel* const model= wid.model();
                                        model->insertRows(0,5);
                                        QPixmap tempPix(30,30);
                                        const Qt::GlobalColor colors[] = {Qt::yellow,Qt::magenta,Qt::cyan,Qt::green,Qt::blue};
                                        for(int i=0;i<wid.count();++i){
                                            tempPix.fill(colors[i]);
                                            model->setData(model->index(i,0),tempPix,Qt::DecorationRole);
                                            model->setData(model->index(i,0),i+1,Qt::EditRole);
                                        }
                                        wid.show();
                                        return application.exec();
                                    }
                                    

                                    "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                                    ~Napoleon Bonaparte

                                    On a crusade to banish setIndexWidget() from the holy land of Qt

                                    1 Reply Last reply
                                    2

                                    1/17

                                    12 Jun 2018, 06:43

                                    • Login

                                    • Login or register to search.
                                    1 out of 17
                                    • First post
                                      1/17
                                      Last post
                                    0
                                    • Categories
                                    • Recent
                                    • Tags
                                    • Popular
                                    • Users
                                    • Groups
                                    • Search
                                    • Get Qt Extensions
                                    • Unsolved