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 add a combobox in qtablewidget?
Forum Updated to NodeBB v4.3 + New Features

How to add a combobox in qtablewidget?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 19.1k Views 2 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.
  • M Offline
    M Offline
    MasterBlade
    wrote on last edited by
    #1

    Hello, I want to add a combobox in qtablewidget. I searched the internet but only found 1 sample in pyqt. Any help for Qt5?

    https://stackoverflow.com/questions/30457935/pyqt4-adding-combobox-in-qtableview

    1 Reply Last reply
    0
    • M Offline
      M Offline
      Mr Gisa
      wrote on last edited by Mr Gisa
      #2

      If you read the code carefully you will notice that it doesn't have that much difference between the C++ and Python in that case as Qt maintain its API for both language.

      The secret lies here: setCellWidget. https://doc.qt.io/qt-5/qtablewidget.html#setCellWidget

      M 1 Reply Last reply
      0
      • M Mr Gisa

        If you read the code carefully you will notice that it doesn't have that much difference between the C++ and Python in that case as Qt maintain its API for both language.

        The secret lies here: setCellWidget. https://doc.qt.io/qt-5/qtablewidget.html#setCellWidget

        M Offline
        M Offline
        MasterBlade
        wrote on last edited by
        #3

        @MasterBlade said in How to add a combobox in qtablewidget?:

        Hello, I want to add a combobox in qtablewidget. I searched the internet but only found 1 sample in pyqt. Any help for Qt5?

        https://stackoverflow.com/questions/30457935/pyqt4-adding-combobox-in-qtableview

        Yes I finally found it. Thanks for that.

        My problem is that I can't locale the row# of the table.

        I used the followings. But only get -1 for row.

        QModelIndex index = ui->Subtype->indexAt(mapFromGlobal(QCursor::pos()));
        int row = index.row();

        The table is only a part of the window. Will that matter?
        0_1524979704641_Capture.PNG

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

          The correct way is using a delegate, see https://forum.qt.io/topic/88486/dropdown-in-qtablewdget/3. You just need to translate that into python

          "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

          • Login

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