Listview in icon mode - text reappears to the right when double clicked [Solved]
-
wrote on 27 Dec 2013, 08:38 last edited by
Hello,
I have a listview that uses QStandardItemModel. The QStandardItemModel is populated with QStandardItem with icons and text. Whenever i double click an icon, the text reappears to the right of the icon. Has anyone encountered something like this? Is there a way to avoid this issue? I'm using Qt 5.1.1 (MSVC 2010, 32 bit) on Windows 7.
Here is the relevant code:
@ QStandardItemModel *testListModel = new QStandardItemModel;
testListModel->setRowCount(4); QStandardItem *f = new QStandardItem(QIcon(":/Test/icons/Wooden_Log-icon.png"),"Log"); QStandardItem *g = new QStandardItem(QIcon(":/Test/icons/warehouse.png"), "Warehouse"); QStandardItem *h = new QStandardItem(QIcon(":/Test/icons/wallet.png"), "Wallet"); QStandardItem *i = new QStandardItem(QIcon(":/Test/icons/visa_512.png"), "Visa"); testListModel->setItem(0, 0, f); testListModel->setItem(1, 0, g); testListModel->setItem(2, 0, h); testListModel->setItem(3, 0, i); ui->bottomListView->setViewMode(QListView::IconMode); ui->bottomListView->setIconSize(QSize(128, 128)); ui->bottomListView->setResizeMode(QListView::Adjust); ui->bottomListView->setModel(testListModel);@
Here are the links to the screenshots:
![url=http://postimage.org/][img]http://s17.postimg.org/noo8lpki7/List_View_1.jpg[/img]/url!
![url=http://postimage.org/][img=http://s8.postimg.org/i0izw3ff9/List_View_2.jpg]/url!
-
wrote on 27 Dec 2013, 09:54 last edited by
What u have written in your Pushbutton Clicked or if you connected to it from signal slot ; write the discription ;
-
wrote on 27 Dec 2013, 10:06 last edited by
It is on the mainwindow's constructor. Here is the full code.
@MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);QFont testFont = font(); testFont.setBold(true); testFont.setPointSizeF(22.0); ui->leftMenuListWidget->setIconSize(QSize(48, 48)); QListWidgetItem *a = new QListWidgetItem("Cargo"); QListWidgetItem *b = new QListWidgetItem(QIcon(":/Test/icons/centos.png"), "CentOS"); QListWidgetItem *c = new QListWidgetItem(QIcon(":/Test/icons/user.png"), "User");
// a->setFont(testFont);
//a->setIcon(QIcon("D:\Dev\Qt\TestListView\icons\Address-Book-1.ico"));a->setIcon(QIcon(":/Test/icons/cargo.png")); a->setSizeHint(QSize(48,48)); ui->leftMenuListWidget->insertItem(0, a); ui->leftMenuListWidget->insertItem(1, b); ui->leftMenuListWidget->insertItem(2, c); this->setWindowIcon(QIcon("D:\\Dev\\Qt\\TestListView\\icons\\clock_.png")); qDebug() << a->icon() << b->icon() << c->icon(); qDebug() << ui->leftMenuListWidget->iconSize(); ui->label->setPixmap(QPixmap(":/Test/icons/Scribal.png")); QFile mFile(":/Test/icons/test.txt"); mFile.open(QFile::ReadOnly | QFile::Text); QTextStream in(&mFile); QString rFile = in.readAll(); qDebug() << rFile; QListWidgetItem *d = new QListWidgetItem("Check Box"); QListWidgetItem *e = new QListWidgetItem("Chair"); ui->rightMenuListWidget->setViewMode(QListWidget::IconMode); ui->rightMenuListWidget->setIconSize(QSize(128,128)); ui->rightMenuListWidget->setResizeMode(QListWidget::Adjust); d->setIcon(QIcon(":/Test/icons/check_box.png")); d->setSizeHint(QSize(64, 64)); ui->rightMenuListWidget->insertItem(0, d); e->setIcon(QIcon(":/Test/icons/chair.png")); e->setSizeHint(QSize(64, 64)); ui->rightMenuListWidget->insertItem(1, e); QStandardItemModel *testListModel = new QStandardItemModel; testListModel->setRowCount(4); QStandardItem *f = new QStandardItem(QIcon(":/Test/icons/Wooden_Log-icon.png"),"Log"); QStandardItem *g = new QStandardItem(QIcon(":/Test/icons/warehouse.png"), "Warehouse"); QStandardItem *h = new QStandardItem(QIcon(":/Test/icons/wallet.png"), "Wallet"); QStandardItem *i = new QStandardItem(QIcon(":/Test/icons/visa_512.png"), "Visa"); //f->setIcon(); //g->setIcon(); //h->setIcon(); //i->setIcon(); testListModel->setItem(0, 0, f); testListModel->setItem(1, 0, g); testListModel->setItem(2, 0, h); testListModel->setItem(3, 0, i); ui->bottomListView->setViewMode(QListView::IconMode); //ui->bottomListView->setIconSize(QSize(128, 128)); ui->bottomListView->setResizeMode(QListView::Adjust); ui->bottomListView->setModel(testListModel);
}
@The icons I used were of different sizes. I tried using icons with similar sizes but the result was the same.
-
Hi,
Does it also happen if you set the grid size ?
-
wrote on 28 Dec 2013, 00:47 last edited by
Yes it still happens. I used 32 x 32 icons then set the gridsize to (48, 48):
@ ui->bottomListView->setViewMode(QListView::IconMode);
ui->bottomListView->setGridSize(QSize(48, 48));
ui->bottomListView->setIconSize(QSize(128, 128));
ui->bottomListView->setResizeMode(QListView::Adjust);
ui->bottomListView->setModel(testListModel);@When I tried setting the gridsize to (32, 32), The bottom text is hidden but when the icons are double clicked it still appears to the right.
I also tried changing the order of execution like setting the gridsize after assigning the model. I also tried not setting an icon size and setting the grid size before setting the view mode.
Hopefully, someone could point me in the right direction. Meanwhile, I'll check the QListView documentation to see if there's anything else I could try.
-
wrote on 28 Dec 2013, 01:05 last edited by
Hello,
I noticed just now that when I click on an item, the text that appears to the right is editable so I just set the QListView to be uneditable:
@ui->bottomListView->setEditTriggers(QAbstractItemView::NoEditTriggers);@
Now, the text no longer reappears to the right.
Thanks for the replies.
-
You're welcome !
Did you meant double-click ?
-
wrote on 2 Jan 2014, 02:29 last edited by
Yes. Double click.
It was supposed to be a prompt to edit the text.
7/8