Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. International
  3. Italian
  4. Come ordinare un elenco di date QListWidget
Forum Updated to NodeBB v4.3 + New Features

Come ordinare un elenco di date QListWidget

Scheduled Pinned Locked Moved Solved Italian
3 Posts 2 Posters 673 Views
  • 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.
  • blackout69B Offline
    blackout69B Offline
    blackout69
    wrote on last edited by
    #1

    Ciao a tutti,
    dopo aver inserito un elenco di date in un QListWidget, vorrei ordinarle in base alla data.
    Sto usando questo codice semplificato

    ui->list->addItem("14-07-2021");
    ui->list->addItem("27-06-2021");
    ui->list->addItem("23-07-2021");
    ui->list->sortItems();
    
    

    Ma vedo che ordina in base al giorno
    14-07-2021
    23-07-2021
    27-06-2021
    e non come vorrei io, in base alla data.

    Qualcuno saprebbe indicarmi un modo per ordinare in base alla data?
    Grazie anticipatamente.

    blackout69

    1 Reply Last reply
    0
    • blackout69B Offline
      blackout69B Offline
      blackout69
      wrote on last edited by
      #3

      Grazie VRonin,
      così funziona.

      1 Reply Last reply
      0
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by VRonin
        #2

        Salva le date come date invece che come stringhe:

        QListWidgetItem *item = new QListWidgetItem;
        item->setData(Qt::EditRole,QDate(2021,7,14));
        ui->list->addItem(item);
        item = new QListWidgetItem;
        item->setData(Qt::EditRole,QDate(2021,6,27));
        ui->list->addItem(item);
        item = new QListWidgetItem;
        item->setData(Qt::EditRole,QDate(2021,7,23));
        ui->list->addItem(item);
        ui->list->sortItems();
        

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        1 Reply Last reply
        0
        • blackout69B Offline
          blackout69B Offline
          blackout69
          wrote on last edited by
          #3

          Grazie VRonin,
          così funziona.

          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