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. create checkboxes at run time
Forum Updated to NodeBB v4.3 + New Features

create checkboxes at run time

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 548 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.
  • G Offline
    G Offline
    GunkutA
    wrote on last edited by GunkutA
    #1

    Hello, I have a QtableWidget and I when I receive a new data from Serial Port I create a new row in it with the data received. I want to create a new checkbox to QTableWidget's 4. column. The main purpose of checkboxes will be this: When pressed to a corresponding button, the row with the checkboxes checked will be transferred to another table. However, this method looks inefficient because then I need to create new checkboxes at run time as this: ( Because I do not know how many data I will receive from serial)

    QCheckBox *checkbox = new QCheckBoxthis);
    

    Then how will I be able to check if these checkboxes are checked or not? Since they don't have a name?
    So I am sure there are lots of better and easier methods for this purpose. What else I can use for that? Or how can I control the checkboxes created at runtime ?

    JonBJ 1 Reply Last reply
    0
    • G GunkutA

      Hello, I have a QtableWidget and I when I receive a new data from Serial Port I create a new row in it with the data received. I want to create a new checkbox to QTableWidget's 4. column. The main purpose of checkboxes will be this: When pressed to a corresponding button, the row with the checkboxes checked will be transferred to another table. However, this method looks inefficient because then I need to create new checkboxes at run time as this: ( Because I do not know how many data I will receive from serial)

      QCheckBox *checkbox = new QCheckBoxthis);
      

      Then how will I be able to check if these checkboxes are checked or not? Since they don't have a name?
      So I am sure there are lots of better and easier methods for this purpose. What else I can use for that? Or how can I control the checkboxes created at runtime ?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @GunkutA
      Before you need to go in this direction: QTableWidgetItems have a checkstate, you can enable via Qt::ItemIsUserCheckable in flags. If you use that you won't have to mess with QCheckBox widgets.

      G 2 Replies Last reply
      2
      • JonBJ JonB

        @GunkutA
        Before you need to go in this direction: QTableWidgetItems have a checkstate, you can enable via Qt::ItemIsUserCheckable in flags. If you use that you won't have to mess with QCheckBox widgets.

        G Offline
        G Offline
        GunkutA
        wrote on last edited by
        #3

        @JonB Thanks. But I use CellDoubleClicked signals of the QTableWidget. So if a cell doubleclicked and user presses enter button, I send the data in the double clicked (selected) cell. So I believe I cannot use checkstate of the QTableWidgetItem. I believe they would interfere eachother.

        JonBJ 1 Reply Last reply
        0
        • JonBJ JonB

          @GunkutA
          Before you need to go in this direction: QTableWidgetItems have a checkstate, you can enable via Qt::ItemIsUserCheckable in flags. If you use that you won't have to mess with QCheckBox widgets.

          G Offline
          G Offline
          GunkutA
          wrote on last edited by
          #4

          @JonB Or actually I can select them with a button I believe.Thanks for the idea!

          1 Reply Last reply
          0
          • G GunkutA

            @JonB Thanks. But I use CellDoubleClicked signals of the QTableWidget. So if a cell doubleclicked and user presses enter button, I send the data in the double clicked (selected) cell. So I believe I cannot use checkstate of the QTableWidgetItem. I believe they would interfere eachother.

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #5

            @GunkutA
            I don't claim to know about that. I still would be reluctant to put a checkbox widget on when there's an in-built, but let's assume that is what you want.

            There are several ways you can do this, and still address

            Then how will I be able to check if these checkboxes are checked or not? Since they don't have a name?

            For simplicity, let's assume you add the QCheckBox onto the cells (setCellWidget()). Then you can access that checkbox via QWidget *QTableWidget::cellWidget(int row, int column) const. qobject_cast() the widget to QCheckBox * to see if it's a checkbox. Is that what you had in mind?

            G 1 Reply Last reply
            0
            • JonBJ JonB

              @GunkutA
              I don't claim to know about that. I still would be reluctant to put a checkbox widget on when there's an in-built, but let's assume that is what you want.

              There are several ways you can do this, and still address

              Then how will I be able to check if these checkboxes are checked or not? Since they don't have a name?

              For simplicity, let's assume you add the QCheckBox onto the cells (setCellWidget()). Then you can access that checkbox via QWidget *QTableWidget::cellWidget(int row, int column) const. qobject_cast() the widget to QCheckBox * to see if it's a checkbox. Is that what you had in mind?

              G Offline
              G Offline
              GunkutA
              wrote on last edited by
              #6

              @JonB Yes it was. But when there will be 100 rows. Checking all of them and creating 100 of checkboxes would be nonsense. I will go with your suggestion.

              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