Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Not on an item in QListWidget
Forum Updated to NodeBB v4.3 + New Features

Not on an item in QListWidget

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 4 Posters 293 Views 1 Watching
  • 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.
  • G Offline
    G Offline
    gabello306
    wrote on last edited by
    #1

    Above a QListWidget I must display an index number of the item in the list. I am able to accomplish this using

        connect ( ui->aoList, &QListWidget::itemEntered, this, &NotebookView::OnMouse );
    

    and using the following to display the index:

    void Common::AO_MouseHover ( QListWidgetItem* item )
     {
            // Show the display index
            m_pGlobal->ao_data.dspIndex->show ();
    
            // Get the index of the item selected
            int32_t row = m_pGlobal->ao_data.list->row ( item );
    
            // Convert the integer to string
            QString idx = QString::number ( row + 1 );
    
            // Set the index value
            m_pGlobal->ao_data.dspIndex->setText ( "# " + idx );
    }
    

    This works great but when I am in the QListWidget and not on an item, I need the display index to disappear. I can't use itemEntered because it only triggers when on an item. Any Ideas?

    Pl45m4P JonBJ 2 Replies Last reply
    0
    • G gabello306

      Above a QListWidget I must display an index number of the item in the list. I am able to accomplish this using

          connect ( ui->aoList, &QListWidget::itemEntered, this, &NotebookView::OnMouse );
      

      and using the following to display the index:

      void Common::AO_MouseHover ( QListWidgetItem* item )
       {
              // Show the display index
              m_pGlobal->ao_data.dspIndex->show ();
      
              // Get the index of the item selected
              int32_t row = m_pGlobal->ao_data.list->row ( item );
      
              // Convert the integer to string
              QString idx = QString::number ( row + 1 );
      
              // Set the index value
              m_pGlobal->ao_data.dspIndex->setText ( "# " + idx );
      }
      

      This works great but when I am in the QListWidget and not on an item, I need the display index to disappear. I can't use itemEntered because it only triggers when on an item. Any Ideas?

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by
      #2

      @gabello306 said in Not on an item in QListWidget:

      when I am in the QListWidget and not on an item, I need the display index to disappear

      When you don't hover any item how should the widget know what index to display?
      Don't really understand what you are trying but maybe using an event filter for your QListWidget helps


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      1 Reply Last reply
      0
      • C Offline
        C Offline
        ChrisW67
        wrote on last edited by
        #3

        Why not use the item model to do it?

        #include <QApplication>
        #include <QListWidget>
        
        int main(int argc, char **argv) {
                QApplication app(argc, argv);
                QListWidget list;
        
                for (int row = 0; row < 10; ++row) {
                        QListWidgetItem *item = new QListWidgetItem(QString("Example %1").arg(row), &list);
                        item->setData(Qt::ToolTipRole, QString("Row %1").arg(row));
                        list.addItem(item); 
                }
        
                list.resize(200, 600);
                list.show();
                return app.exec();
        }
        

        8070b41e-481e-4daf-9ea9-6a367651f33c-image.png

        1 Reply Last reply
        2
        • G gabello306

          Above a QListWidget I must display an index number of the item in the list. I am able to accomplish this using

              connect ( ui->aoList, &QListWidget::itemEntered, this, &NotebookView::OnMouse );
          

          and using the following to display the index:

          void Common::AO_MouseHover ( QListWidgetItem* item )
           {
                  // Show the display index
                  m_pGlobal->ao_data.dspIndex->show ();
          
                  // Get the index of the item selected
                  int32_t row = m_pGlobal->ao_data.list->row ( item );
          
                  // Convert the integer to string
                  QString idx = QString::number ( row + 1 );
          
                  // Set the index value
                  m_pGlobal->ao_data.dspIndex->setText ( "# " + idx );
          }
          

          This works great but when I am in the QListWidget and not on an item, I need the display index to disappear. I can't use itemEntered because it only triggers when on an item. Any Ideas?

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @gabello306
          @ChrisW67's suggestion is indeed the simplest if you are willing to assign static tooltips to existing items in the list, and recommended if that is the case. However it will require some further work if you insert, delete or move items in your list. Do you need that, or is the list fixed? It also displays the information as a popup tooltip over each item rather than your original requested "Above a QListWidget I must display an index number" so depends whether you mind about that.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved