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. How to show a list in a QTableWidgetItem item?

How to show a list in a QTableWidgetItem item?

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 536 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.
  • canellasC Offline
    canellasC Offline
    canellas
    wrote on last edited by
    #1

    I have a QTableWidget with 2 columns: name and year of birth. The user will input its name, but I would like to show a list of years in year of birth column, so that he/she could select from it.

    I probably did not search correctly, as I could not find any explanation or example.

    Could anyone provide an example/link of how can I do it?

    Thanks!

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

      Hi and welcome to devnet,

      You can make a custom QStyledItemDelegate and in the createEditor method create a QComboBox containing the list of dates you want.

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

      canellasC 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi and welcome to devnet,

        You can make a custom QStyledItemDelegate and in the createEditor method create a QComboBox containing the list of dates you want.

        canellasC Offline
        canellasC Offline
        canellas
        wrote on last edited by
        #3

        @SGaist ,

        Thanks a lot for your time!

        I used QTableWidget::setWidget instead of QTableWidget::setItem to set a QComboBox in the cell, and it worked fine:

              QComboBox* _list = new QComboBox();
              _list->addItem("A");
              _list->addItem("B");
              _list->addItem("C");
              ui->tblPks->setCellWidget(_row, 4, (QWidget*)_list);
        

        img00.png

        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