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.8k 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.
  • 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