Results 1 to 3 of 3

Thread: How do I display a list of images?

  1. #1
    Join Date
    Feb 2006
    Posts
    209
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How do I display a list of images?

    I've tried to put them into a QListWidget as icons in ordinary items, but they get too small. I wish to have them 50x50 pixels.
    How can I get them in that size?

  2. #2
    Join Date
    Nov 2007
    Posts
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How do I display a list of images?

    Hi,

    QListWidget has a property inherited from QAbstractItemView: iconSize
    call setIconSize(QSize(x,y)) to change the size of the icons in the list, that worked for me

  3. #3
    Join Date
    Jul 2007
    Posts
    166
    Thanks
    25
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How do I display a list of images?

    Hi,
    Try this code. It will help you


    in your header file

    enum { NumModes = 4, NumStates = 2 };
    QStringList files;
    QStringList filters;
    QString fileName;
    QDir directory;
    QPixmap pixmap ;
    int r, c, NumStates_New, HEIGHT;
    QGridLayout *SnapLayout;
    QIcon icon;
    QSize size;
    QLabel *pixmapLbl;




    void YourClass::LoadImages(){

    int COLUMN;
    filters << "Picture*" ;
    directory.setNameFilters(filters);
    files = directory.entryList(filters, QDir::Files | QDir::NoSymLinks);
    c=0; COLUMN = 2;
    NumStates_New = 0;
    NumStates_New = files.size()/2;
    if ( files.size()%2 >0 ) NumStates_New++;

    QLabel *pixmapLabels [NumStates_New] [2];
    pixmapLabels [NumStates_New] [2];

    for (int i = 0; i < NumStates_New; ++i) {
    for (int j = 0; j < COLUMN; ++j) {
    pixmapLabels[i][j] = createPixmapLabel();
    pixmapLabels[i][j]->resize(5,5);
    SnapLayout->addWidget(pixmapLabels[i][j], i + 1, j + 1 );
    }
    }

    r=0, c=0;
    for (int i = 0; i < files.size(); ++i) {
    fileName = files.at(i).toLocal8Bit().constData(); QImage image(fileName);

    if (!image.isNull()){
    icon.addPixmap(QPixmap::fromImage(image), QIcon::Normal, QIcon::On);
    }

    this->icon = icon;
    this->size = QSize(110,102);
    QPixmap pixmap = icon.pixmap(size, QIcon::Normal, QIcon::On);
    pixmapLabels[r][c]->setPixmap(pixmap);
    pixmapLabels[r][c]->setToolTip(fileName);
    c++; if (c>=COLUMN) { c=0; r++; }
    } }



    QLabel *YourClass::createPixmapLabel()
    {
    QLabel *label = new QLabel;
    label->setEnabled(true);
    label->setAlignment(Qt::AlignCenter);
    label->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    label->setAutoFillBackground(true);
    label->setMinimumSize(110,102);
    return label;
    }


    and Call this function in your program

Similar Threads

  1. Replies: 1
    Last Post: 22nd October 2007, 03:04
  2. Is there any way to synchronize the display of images
    By kiransu123 in forum General Programming
    Replies: 2
    Last Post: 17th March 2007, 21:50
  3. Display multiple Images in a widget
    By jeetu_happy in forum Qt Programming
    Replies: 2
    Last Post: 7th March 2007, 12:24
  4. Display animated images
    By suresh in forum Qt Programming
    Replies: 1
    Last Post: 27th January 2007, 22:53
  5. How to display images in QTextBrowser ?
    By probine in forum Qt Programming
    Replies: 1
    Last Post: 12th January 2007, 09:58

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.