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. [SOLVED] QCheckBox in a QTableWidget
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] QCheckBox in a QTableWidget

Scheduled Pinned Locked Moved General and Desktop
8 Posts 4 Posters 8.9k 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.
  • X Offline
    X Offline
    xeroblast
    wrote on last edited by
    #1

    i created a simple loop in a QTableWidget with checkboxes but i dont know how i get their objectnames.

    @
    for (int i=0; i < total_items; i++) {
    QCheckBox *cb = new QCheckBox();
    tableWidget->setCellWidget(i, 0, cb);
    tableWidget->setItem(i, 1, new QTableWidgetItem("name" + i));
    }
    @

    when i click the OK button, i want to detect if the checkboxes are checked or not but i dont have any idea how to get their objectnames.

    hope you could give some advices on how to deal with this. thank you.

    1 Reply Last reply
    0
    • X Offline
      X Offline
      xeroblast
      wrote on last edited by
      #2

      i tried using QSignalMapper but i only know QSignalMapper using strings but with boolean, i dont know..

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on last edited by
        #3

        You can simply loop over the items again, right? Either you store pointers to the checkboxes separately (in a QList<QCheckBox*> or a QVector<QCheckBox*>, or you simply retreive the pointer to the widget again from your tablewidgetitem and cast it to a QCheckBox* again.

        Note: QTableWidget can also display checkboxes by itself. No separate widgets needed...

        1 Reply Last reply
        0
        • X Offline
          X Offline
          xeroblast
          wrote on last edited by
          #4

          thanks for giving me an idea.

          1 Reply Last reply
          0
          • G Offline
            G Offline
            goetz
            wrote on last edited by
            #5

            Do you know of the "Qt::ItemIsUserCheckable":http://doc.qt.nokia.com/4.7/qt.html#ItemFlag-enum flag for table wiget items (and all other item view/widget classes)?

            http://www.catb.org/~esr/faqs/smart-questions.html

            1 Reply Last reply
            0
            • P Offline
              P Offline
              poketmonister
              wrote on last edited by
              #6

              can QTableWidget display checkboxes by itself without the need of seperate widgets ?
              plz tell me how.

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andre
                wrote on last edited by
                #7

                [quote author="poketmonister" date="1396440874"]can QTableWidget display checkboxes by itself without the need of seperate widgets ?
                plz tell me how.[/quote]

                Yes, and the link Volker gave tells you how.

                1 Reply Last reply
                0
                • P Offline
                  P Offline
                  poketmonister
                  wrote on last edited by
                  #8

                  i'll checkout Qt::ItemIsUserCheckable .

                  by the way QList<QCheckBox*> worked wonders thanks.

                  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