Thank so much for all the replies. and sadly I lost again at the "Fourth of all".
I am completely new to Qt, and have been trying to get this working for the last two days. Lets me explain what I want to do.
What I have is a class in which I added a QListview and populate it with images
The ListModel I created, in case you need to have a look
//List Model
{
public:
{
size = 72;
QDirIterator it(srcPath);
while (it.hasNext()) {
if (file.endsWith(".jpg"))
{
m_values << file;
}
}
}
{
return m_values.count();
}
{
if (role == Qt::DecorationRole)
{
pixmap = pixmap.scaled( size, size, Qt::AspectRatioMode::KeepAspectRatio);
return pixmap;
}
if( role != Qt::DisplayRole && role != Qt::EditRole )
if( index.column() == 0 && index.row() < m_values.count() )
return ""; //Text here
else
}
private:
QList<QString > m_values;
int size;
};
//List Model
class ListModel : public QAbstractListModel
{
public:
ListModel(QString srcPath) : QAbstractListModel()
{
size = 72;
QDirIterator it(srcPath);
while (it.hasNext()) {
QString file = it.next();
if (file.endsWith(".jpg"))
{
m_values << file;
}
}
}
int rowCount(QModelIndex const & index) const
{
return m_values.count();
}
QVariant data(QModelIndex const & index, int role) const
{
if (role == Qt::DecorationRole)
{
QPixmap pixmap = QPixmap(m_values.at(index.row()));
pixmap = pixmap.scaled( size, size, Qt::AspectRatioMode::KeepAspectRatio);
return pixmap;
}
if( role != Qt::DisplayRole && role != Qt::EditRole )
return QVariant();
if( index.column() == 0 && index.row() < m_values.count() )
return ""; //Text here
else
return QVariant();
}
private:
QList<QString > m_values;
int size;
};
To copy to clipboard, switch view to plain text mode
Then creating the list
QLayout* TransFuncEditorIntensityTexture
::createColorLayout() {
const QString rscPath
= "../../data/3DTextures/";
list->setFixedWidth(100);
list->setWrapping(FALSE);
list->setModel(new ListModel(rscPath));
hBox->addWidget(list);
if (orientation_ == Qt::Vertical)
return hBox;
else {
vbox->addLayout(hBox, 1);
vbox->addStretch();
return vbox;
}
return hBox;
}
QLayout* TransFuncEditorIntensityTexture::createColorLayout() {
const QString rscPath = "../../data/3DTextures/";
list = new QListView();
list->setViewMode(QListView::IconMode);
list->setFlow(QListView::TopToBottom);
list->setFixedWidth(100);
list->setWrapping(FALSE);
list->setModel(new ListModel(rscPath));
QHBoxLayout* hBox = new QHBoxLayout();
hBox->addWidget(list);
if (orientation_ == Qt::Vertical)
return hBox;
else {
QVBoxLayout* vbox = new QVBoxLayout();
vbox->addLayout(hBox, 1);
vbox->addStretch();
return vbox;
}
return hBox;
}
To copy to clipboard, switch view to plain text mode
And this is what I got
List.png
Now all what I want is when the user click on one of the image, I am notified (any particular method is called) . That is all, really. I guess its probably simpler than I expected but still. I have been trying all kinds of thing and currently. This is what I have
connect(list, SIGNAL(selectionChanged ( QListViewItem* )), this, SLOT(selectionList( QListViewItem* )));
void TransFuncEditorIntensityTexture::selectionList(QListViewItem* item)
{
//Just make sure this method is called. but it never happens
list->setDisabled(true);
}
connect(list, SIGNAL(selectionChanged ( QListViewItem* )), this, SLOT(selectionList( QListViewItem* )));
void TransFuncEditorIntensityTexture::selectionList(QListViewItem* item)
{
//Just make sure this method is called. but it never happens
list->setDisabled(true);
}
To copy to clipboard, switch view to plain text mode
within TransFuncEditorIntensityTexture class definition, I have
public slots:
void selectionList(QListViewItem*);
public slots:
void selectionList(QListViewItem*);
To copy to clipboard, switch view to plain text mode
I have been reading Slot and Signal article, running back and forth on the net. Could you guys please let me know what I am missing? or point me to where I can find the information.
Really appriciate it
Bookmarks