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. void QTableWidget::sortItems

void QTableWidget::sortItems

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 2 Posters 2.0k 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.
  • S Offline
    S Offline
    stephane78
    wrote on last edited by
    #1

    HI, it seems that this function see that "999999" is greater than "1000000" because there are only QString and not numbers(long...) in the QTableWIdgetItem.
    SO I should sort my list before to put it in the QTableWIdgetItem, and I should not use this method void QTableWidget::sortItems
    is this a bug of Qt?

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

      QTableWidget compares according to QVariant http://doc.qt.io/qt-5/qvariant.html#operator-lt if you pass the numbers as strings they will be sorted as strings.

      how do you insert data in the QTableWidget?

      "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
      1
      • S Offline
        S Offline
        stephane78
        wrote on last edited by stephane78
        #3
        setItem(i,1,new QTableWidgetItem(QString::number(penv->getId())));
        

        where getId() returns a long,but I insert it as a QString and I don't see any other choice because the constructor of QTableWIdgetItem takes a QString and not a number.

        1 Reply Last reply
        0
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #4
          QTableWidgetItem* tempItem new QTableWidgetItem;
          tempItem->setData(Qt::DisplayRole,penv->getId());
          setItem(i,1,tempItem);
          

          "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
          2
          • S Offline
            S Offline
            stephane78
            wrote on last edited by
            #5

            @VRonin , HI, thank you I didn't know that.But this column is hidden.does it matter ?

            VRoninV 1 Reply Last reply
            0
            • S stephane78

              @VRonin , HI, thank you I didn't know that.But this column is hidden.does it matter ?

              VRoninV Offline
              VRoninV Offline
              VRonin
              wrote on last edited by
              #6

              @stephane78 said:

              this column is hidden.does it matter ?

              No, hiding the column depends on the view, the data in the column depends on the model so no direct implication. see Model/View Programming

              "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
              1
              • S Offline
                S Offline
                stephane78
                wrote on last edited by stephane78
                #7

                @VRonin, ok thank you .do you think that sortItems will run correctly by this way (by putting a number in the column) ?

                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