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. QTableWidget items selection

QTableWidget items selection

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 2.8k 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.
  • AbderaoufA Offline
    AbderaoufA Offline
    Abderaouf
    wrote on last edited by
    #1

    Gents;

    I am doing an exercice using QTableWidget when I have to select one item from four in each row of the first column. Lets say I have 10 rows and 3 columns. I thought of crearing a QStringList that I attribute to each row and select the item, like QCombo Box widget.

    I have prepared the below exemple; please advise:

    list->append("Item 1");
    list->append("Item 2");
    list->append("Item 3");
    list->append("Item 4");

    for(int i = 0; i < 1; i++ )
    {
    for (int j = 0; j < 11; j++)
    {
    Stagetype = new QTableWidgetItem (QStringList (list));
    ui->table_ConvDesign->setItem(i,j,list);
    }
    }

    Cheers;

    Raouf

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Advise what exactly ?

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

      AbderaoufA 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Advise what exactly ?

        AbderaoufA Offline
        AbderaoufA Offline
        Abderaouf
        wrote on last edited by
        #3

        @SGaist
        When running this code I had a couple of error messages. I am not sure this is the proper way to proceed.

        Cheers

        mrjjM 1 Reply Last reply
        0
        • AbderaoufA Abderaouf

          @SGaist
          When running this code I had a couple of error messages. I am not sure this is the proper way to proceed.

          Cheers

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #4

          @Abderaouf
          Hi, if you list the actual errors we can help make them go away :)
          (you can right click error and say copy, in Creator)

          Also
          https://wiki.qt.io/How_to_Use_QTableWidget

          Your sample seems to be missing
          m_pTableWidget->setRowCount(XXX);
          m_pTableWidget->setColumnCount(XXX);
          This is important as nothing will show otherwise :)

          AbderaoufA 1 Reply Last reply
          2
          • mrjjM mrjj

            @Abderaouf
            Hi, if you list the actual errors we can help make them go away :)
            (you can right click error and say copy, in Creator)

            Also
            https://wiki.qt.io/How_to_Use_QTableWidget

            Your sample seems to be missing
            m_pTableWidget->setRowCount(XXX);
            m_pTableWidget->setColumnCount(XXX);
            This is important as nothing will show otherwise :)

            AbderaoufA Offline
            AbderaoufA Offline
            Abderaouf
            wrote on last edited by
            #5

            @mrjj this is my code:

            void CFAdvisor::setupTableItems()
            {
            for (int row = 0; row < table_ConvDesign->rowCount()-1; ++row)
            {
            for (int column = 0; column < table_ConvDesign->columnCount()< 0; ++column)
            {
            QStringList list;
            list->append("Pre-PAD");
            list->append("PAD");
            list->append("SLF");
            list->append("Flush");
            table_ConvDesign->setItem(row, column, &list);
            }
            and this is the error:
            E:\Computing\Qt Designer\cfadvisor.cpp:168: erreur : no matching function for call to 'QTableWidget::setItem(int&, int&, QStringList
            *)'
            table_ConvDesign->setItem(row, column, &list);
            ^

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              setItem takes a QTableWidgetItem * not a QStringList *.

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

              AbderaoufA 1 Reply Last reply
              1
              • SGaistS SGaist

                setItem takes a QTableWidgetItem * not a QStringList *.

                AbderaoufA Offline
                AbderaoufA Offline
                Abderaouf
                wrote on last edited by
                #7

                @SGaist this is the point; how to make it take a QStringList. This is what I want to do ;)

                mrjjM 1 Reply Last reply
                0
                • AbderaoufA Abderaouf

                  @SGaist this is the point; how to make it take a QStringList. This is what I want to do ;)

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @Abderaouf
                  Hi
                  It does not work that way at all. :)
                  So even its Xmas, it not possible
                  setItem wants an item. not list.
                  the item take some text.
                  so you can use a for loop with the list, and create item for each.
                  It will not do it for you :)

                  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