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:
#include "window.h"
#include <QtGui>
#include <QApplication>
int main(int argc, char *argv[])
{
Window w;
w.show();
return a.exec();
}
#include "window.h"
#include <QtGui>
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Window w;
w.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
window.h:
#ifndef WINDOW_H
#define WINDOW_H
#include <QtGui/QMainWindow>
{
Q_OBJECT
public:
private:
private slots:
void addImage();
};
#endif // WINDOW_H
#ifndef WINDOW_H
#define WINDOW_H
#include <QtGui/QMainWindow>
class QListWidget;
class Window : public QMainWindow
{
Q_OBJECT
public:
Window(QWidget *parent = 0);
private:
QListWidget *thumbsList;
private slots:
void addImage();
};
#endif // WINDOW_H
To copy to clipboard, switch view to plain text mode
window.cpp
#include "window.h"
#include <QtGui>
{
this->resize(640, 480);
this->thumbsList->setFixedHeight(116);
this
->thumbsList
->setGridSize
(QSize(126,
116));
this
->thumbsList
->setIconSize
(QSize(96,
96));
this
->thumbsList
->setFlow
(QListView::LeftToRight);
this->thumbsList->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
this
->thumbsList
->setViewMode
(QListView::IconMode);
connect(addImageButton, SIGNAL(clicked()), this, SLOT(addImage()));
frameLayout->addWidget(addImageButton);
frameLayout->addWidget(this->thumbsList);
this->setCentralWidget(frame);
}
void Window::addImage()
{
item->setFlags(Qt::ItemIsEnabled);
this->thumbsList->addItem(item);
}
#include "window.h"
#include <QtGui>
Window::Window(QWidget *parent)
: QMainWindow(parent)
{
this->resize(640, 480);
QFrame *frame = new QFrame;
QVBoxLayout *frameLayout = new QVBoxLayout(frame);
this->thumbsList = new QListWidget(frame);
this->thumbsList->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Ignored);
this->thumbsList->setFixedHeight(116);
this->thumbsList->setGridSize(QSize(126, 116));
this->thumbsList->setIconSize(QSize(96, 96));
this->thumbsList->setFlow(QListView::LeftToRight);
this->thumbsList->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
this->thumbsList->setViewMode(QListView::IconMode);
QPushButton *addImageButton = new QPushButton(tr("Add image"));
addImageButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
connect(addImageButton, SIGNAL(clicked()), this, SLOT(addImage()));
frameLayout->addWidget(addImageButton);
frameLayout->addWidget(this->thumbsList);
this->setCentralWidget(frame);
}
void Window::addImage()
{
QListWidgetItem *item = new QListWidgetItem(this->thumbsList);
item->setFlags(Qt::ItemIsEnabled);
item->setIcon(QIcon(QPixmap::fromImage(QImage("C:/image.jpg"))));
this->thumbsList->addItem(item);
}
To copy to clipboard, switch view to plain text mode
Bookmarks