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. Issues with QListWidget
Forum Updated to NodeBB v4.3 + New Features

Issues with QListWidget

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 635 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.
  • H Offline
    H Offline
    Hubbard
    wrote on last edited by
    #1

    Hello, i'm trying to use QListWidget for a variety of purposes however it is difficult to work with, I'm having an issue where an uninstanced item is appearing in the list and an instanced one... simply isn't, its very odd and frustrating, please help.

    void UnitWindow::setupDataDisplay()
    {
    tempRibbonAddress = new DataRibbon;
    lightRibbonAddress = new DataRibbon;
    moistureRibbonAddress = new DataRibbon;
    humidityRibbonAddress = new DataRibbon;

    ui->DataList->clear();
    
    QListWidgetItem* tempItemAddress = new QListWidgetItem(ui->DataList);
    tempItemAddress->setSizeHint(tempRibbonAddress->size());
    ui->DataList->setItemWidget(tempItemAddress, tempRibbonAddress);
    ui->DataList->insertItem(0, tempItemAddress);
    
    tempRibbonAddress->setDataTitle("<font color = 'Red'> Temperature </font>");
    
    QListWidgetItem* lightItemAddress = new QListWidgetItem(ui->DataList);
    lightItemAddress->setSizeHint(lightRibbonAddress->size());
    ui->DataList->setItemWidget(lightItemAddress, lightRibbonAddress);
    ui->DataList->insertItem(1, lightItemAddress);
    
    lightRibbonAddress->setDataTitle("<font color = 'Yellow'> Light </font>");
    
    QListWidgetItem* moistureItemAddress = new QListWidgetItem(ui->DataList);
    moistureItemAddress->setSizeHint(moistureRibbonAddress->size());
    ui->DataList->setItemWidget(moistureItemAddress, moistureRibbonAddress);
    ui->DataList->insertItem(2, moistureItemAddress);
    
    moistureRibbonAddress->setDataTitle("<font color = 'Light Green'>Moisture</font>");
    
    QListWidgetItem* humidityItemAddress = new QListWidgetItem(ui->DataList);
    humidityItemAddress->setSizeHint(humidityRibbonAddress->size());
    ui->DataList->setItemWidget(humidityItemAddress, humidityRibbonAddress);
    ui->DataList->insertItem(3, humidityItemAddress);
    
    lightRibbonAddress->setDataTitle("<font color = 'Light Blue'>Humidity</font>");
    

    }

    Produces a list with temperature, humidity and moisture displayed as normal, on rows 0,1,2 (weird), light is not appearing and instead a blank version of the 'DataRibbon' class is appearing with 'TextLabel' in black in place of the Data Title.

    1 Reply Last reply
    0
    • H Offline
      H Offline
      Hubbard
      wrote on last edited by
      #2
      DataRibbon* tempRibbonAddress;
      DataRibbon* lightRibbonAddress;
      DataRibbon* moistureRibbonAddress;
      DataRibbon* humidityRibbonAddress;
      

      Here is the header file declarations of the DataRibbon instances, it is a graphical widget with some QLabels

      K 1 Reply Last reply
      0
      • H Hubbard
        DataRibbon* tempRibbonAddress;
        DataRibbon* lightRibbonAddress;
        DataRibbon* moistureRibbonAddress;
        DataRibbon* humidityRibbonAddress;
        

        Here is the header file declarations of the DataRibbon instances, it is a graphical widget with some QLabels

        K Offline
        K Offline
        kenchan
        wrote on last edited by
        #3

        @Hubbard I think you might be adding the items twice. According to the docs that leads to undefined behaviour.
        The constructor of the QListWidgetItem adds it to its parent. Then it looks like you add it again with setItemWidget, or am I mistaken?
        Can you post your ui file too?

        1 Reply Last reply
        1
        • H Offline
          H Offline
          Hubbard
          wrote on last edited by
          #4

          Nah it was because I set the DataTitle for light twice

          1 Reply Last reply
          1

          • Login

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