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 Updated to NodeBB v4.3 + New Features

Thumbnails using List Widget

Scheduled Pinned Locked Moved Solved General and Desktop
17 Posts 4 Posters 4.0k 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.
  • A amarism

    @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

    mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on last edited by
    #4

    @amarism

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

    A 1 Reply Last reply
    0
    • mrjjM mrjj

      @amarism

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

      A Offline
      A Offline
      amarism
      wrote on 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......)

      mrjjM 1 Reply Last reply
      0
      • A amarism

        @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......)

        mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on 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
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on 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
          0
          • VRoninV VRonin

            Can you show us the content of GenerateThumbList?

            A Offline
            A Offline
            amarism
            wrote on last edited by
            #8

            @VRonin 0_1528796229765_thumbnail.png

            VRoninV 1 Reply Last reply
            0
            • A amarism

              @VRonin 0_1528796229765_thumbnail.png

              VRoninV Offline
              VRoninV Offline
              VRonin
              wrote on 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
              1
              • VRoninV VRonin

                @amarism 😓 I meant the code

                A Offline
                A Offline
                amarism
                wrote on 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));
                }

                VRoninV 1 Reply Last reply
                0
                • A amarism

                  @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));
                  }

                  VRoninV Offline
                  VRoninV Offline
                  VRonin
                  wrote on 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
                  0
                  • VRoninV VRonin

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

                    A Offline
                    A Offline
                    amarism
                    wrote on last edited by
                    #12

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

                    VRoninV 1 Reply Last reply
                    0
                    • A amarism

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

                      VRoninV Offline
                      VRoninV Offline
                      VRonin
                      wrote on last edited by VRonin
                      #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
                      0
                      • VRoninV VRonin

                        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 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 last edited by KillerSmath
                          #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
                          0
                          • KillerSmathK KillerSmath

                            @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 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
                            • VRoninV Offline
                              VRoninV Offline
                              VRonin
                              wrote on last edited by VRonin
                              #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

                              • Login

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