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 get selected item of QTableWidget with QLabel in it
Forum Updated to NodeBB v4.3 + New Features

How to get selected item of QTableWidget with QLabel in it

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 850 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.
  • P Offline
    P Offline
    Pauly
    wrote on last edited by Pauly
    #1

    In my QTableWidget, I fill some cells with QLabel by:

    ui->myTableWidget->setCellWidget(1, 1, new QLabel("test"));
    

    When I click the cells they will show as selected, but I can't seem to get the selection on them by doing:

    ui->myTableWidget->selectedItems()
    

    This will return nothing even a few cells with QLabel in it are actually selected. Is there any way to go around this using QTableWidget? Thanks.

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

      Hi,

      Why are you putting a QLabel in QTableWidget cell to show text since QTableWidget already shows text ?

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

      P 1 Reply Last reply
      2
      • SGaistS SGaist

        Hi,

        Why are you putting a QLabel in QTableWidget cell to show text since QTableWidget already shows text ?

        P Offline
        P Offline
        Pauly
        wrote on last edited by
        #3

        @SGaist I was trying to set font and make them read only?

        jsulmJ 1 Reply Last reply
        0
        • P Pauly

          @SGaist I was trying to set font and make them read only?

          jsulmJ Online
          jsulmJ Online
          jsulm
          Lifetime Qt Champion
          wrote on last edited by jsulm
          #4

          @Pauly You can mark an table item read-only using https://doc.qt.io/qt-5/qt.html#ItemFlag-enum and setFlags()
          For fonts there is https://doc.qt.io/qt-5/qtablewidgetitem.html#setFont

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          P 1 Reply Last reply
          3
          • jsulmJ jsulm

            @Pauly You can mark an table item read-only using https://doc.qt.io/qt-5/qt.html#ItemFlag-enum and setFlags()
            For fonts there is https://doc.qt.io/qt-5/qtablewidgetitem.html#setFont

            P Offline
            P Offline
            Pauly
            wrote on last edited by
            #5

            @jsulm You are right... I'm making this more complicated than it needs to be... Thanks for the advise.

            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