Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Call for Presentations - Qt World Summit

    Listview in icon mode - text reappears to the right when double clicked [Solved]

    General and Desktop
    3
    8
    3075
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • P
      puterk 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!

      1 Reply Last reply Reply Quote 0
      • P
        praveen0991kr last edited by

        What u have written in your Pushbutton Clicked or if you connected to it from signal slot ; write the discription ;

        1 Reply Last reply Reply Quote 0
        • P
          puterk 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&#40;":/Test/icons/test.txt"&#41;;
          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.

          1 Reply Last reply Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            Hi,

            Does it also happen if you set the grid size ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply Reply Quote 0
            • P
              puterk 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.

              1 Reply Last reply Reply Quote 0
              • P
                puterk 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.

                1 Reply Last reply Reply Quote 0
                • SGaist
                  SGaist Lifetime Qt Champion last edited by

                  You're welcome !

                  Did you meant double-click ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply Reply Quote 0
                  • P
                    puterk last edited by

                    Yes. Double click.
                    It was supposed to be a prompt to edit the text.

                    1 Reply Last reply Reply Quote 0
                    • First post
                      Last post