Results 1 to 3 of 3

Thread: QListWidget problem [solved]

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2009
    Posts
    29
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default QListWidget problem [solved]

    Hi,
    I've a problem with QListWidget class. In the following program, when trying to add the 5th image, it goes bottom (it is hidden). My idea is that the 5th and the following images go on the same row with an horizontal scrollbar. Note that if I add 4 images, then I enlarge the window, I add the 5th image and I restore the previous size, the scrollbar appears!
    Can anyone help me solving the problem?

    Thanks! Dario

    (sorry for my bad english)


    main.cpp:
    Qt Code:
    1. #include "window.h"
    2.  
    3. #include <QtGui>
    4. #include <QApplication>
    5.  
    6. int main(int argc, char *argv[])
    7. {
    8. QApplication a(argc, argv);
    9. Window w;
    10. w.show();
    11. return a.exec();
    12. }
    To copy to clipboard, switch view to plain text mode 


    window.h:
    Qt Code:
    1. #ifndef WINDOW_H
    2. #define WINDOW_H
    3.  
    4. #include <QtGui/QMainWindow>
    5.  
    6.  
    7. class Window : public QMainWindow
    8. {
    9. Q_OBJECT
    10.  
    11. public:
    12. Window(QWidget *parent = 0);
    13.  
    14. private:
    15. QListWidget *thumbsList;
    16.  
    17. private slots:
    18. void addImage();
    19. };
    20.  
    21. #endif // WINDOW_H
    To copy to clipboard, switch view to plain text mode 


    window.cpp
    Qt Code:
    1. #include "window.h"
    2.  
    3. #include <QtGui>
    4.  
    5. Window::Window(QWidget *parent)
    6. : QMainWindow(parent)
    7. {
    8. this->resize(640, 480);
    9.  
    10. QFrame *frame = new QFrame;
    11. QVBoxLayout *frameLayout = new QVBoxLayout(frame);
    12.  
    13. this->thumbsList = new QListWidget(frame);
    14. this->thumbsList->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Ignored);
    15. this->thumbsList->setFixedHeight(116);
    16. this->thumbsList->setGridSize(QSize(126, 116));
    17. this->thumbsList->setIconSize(QSize(96, 96));
    18. this->thumbsList->setFlow(QListView::LeftToRight);
    19. this->thumbsList->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    20. this->thumbsList->setViewMode(QListView::IconMode);
    21.  
    22. QPushButton *addImageButton = new QPushButton(tr("Add image"));
    23. addImageButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
    24. connect(addImageButton, SIGNAL(clicked()), this, SLOT(addImage()));
    25.  
    26. frameLayout->addWidget(addImageButton);
    27. frameLayout->addWidget(this->thumbsList);
    28. this->setCentralWidget(frame);
    29. }
    30.  
    31. void Window::addImage()
    32. {
    33. QListWidgetItem *item = new QListWidgetItem(this->thumbsList);
    34. item->setFlags(Qt::ItemIsEnabled);
    35. item->setIcon(QIcon(QPixmap::fromImage(QImage("C:/image.jpg"))));
    36. this->thumbsList->addItem(item);
    37. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by satoshi; 4th May 2009 at 18:58.

Similar Threads

  1. QListWidget SIGNAL Problem
    By skuda in forum Qt Programming
    Replies: 19
    Last Post: 28th October 2009, 14:42
  2. QListWidget - stylesheet problem
    By febil in forum Qt Programming
    Replies: 3
    Last Post: 23rd February 2009, 16:44
  3. Problem with events changing behavior of QListWidget
    By riklaunim in forum Qt Programming
    Replies: 10
    Last Post: 22nd December 2008, 19:10
  4. The problem with the display of QListWidget
    By whyisosad in forum Qt Programming
    Replies: 1
    Last Post: 12th May 2008, 19:41
  5. QListWidget Problem
    By pmabie in forum Qt Programming
    Replies: 1
    Last Post: 7th October 2007, 06:52

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
  •  
Qt is a trademark of The Qt Company.