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. Custom QCheckbox in QT widgets
Forum Updated to NodeBB v4.3 + New Features

Custom QCheckbox in QT widgets

Scheduled Pinned Locked Moved Unsolved General and Desktop
qtwidgetsqcheckboxstylesheetqtablewidget
3 Posts 2 Posters 976 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.
  • E Offline
    E Offline
    EagleSparrow
    wrote on 5 Aug 2020, 14:38 last edited by
    #1

    So;
    I am trying to create a QTableWidget that will have checkboxes in some columns and I have two scenarios. The first I want to have one column with text and a checkbox. The Second scenario, I want to have two columns each with checkboxes.

    I hav this implemented and it works great. However, Now I need to make the checkboxes have custom states that are driven by graphic.svg files for each state. I was hoping to do this with a stylesheet but have had huge trouble. Most examples are kindof QtQuick related and I do not see anything that is in the QtWidgets world.

    Does anyone have any code or example of this?
    I really appreciate any help.
    Thanks!

    J 1 Reply Last reply 5 Aug 2020, 14:50
    0
    • E EagleSparrow
      5 Aug 2020, 14:38

      So;
      I am trying to create a QTableWidget that will have checkboxes in some columns and I have two scenarios. The first I want to have one column with text and a checkbox. The Second scenario, I want to have two columns each with checkboxes.

      I hav this implemented and it works great. However, Now I need to make the checkboxes have custom states that are driven by graphic.svg files for each state. I was hoping to do this with a stylesheet but have had huge trouble. Most examples are kindof QtQuick related and I do not see anything that is in the QtWidgets world.

      Does anyone have any code or example of this?
      I really appreciate any help.
      Thanks!

      J Offline
      J Offline
      JonB
      wrote on 5 Aug 2020, 14:50 last edited by
      #2

      @EagleSparrow said in Custom QCheckbox in QT widgets:

      I hav this implemented and it works great.

      You might want to state, briefly, how you have gone about adding these checkboxes into your QTableWidget?

      1 Reply Last reply
      1
      • E Offline
        E Offline
        EagleSparrow
        wrote on 5 Aug 2020, 15:19 last edited by
        #3

        Here is the code.

        QList<SomeClass> ModeTableEntries ;
        
         for (int row = 0; row < ModeTableEntries .length(); row++)
          {
                        ui->EntriesTableWidget->insertRow(row);
                        ui->EntriesTableWidget->setRowHeight(row, 45);
                       ModeValues value = ModeTableEntries [row];
                        QTableWidgetItem* currentItem = new QTableWidgetItem(value .ModeText);
        
                        if(TestModeEnabled == true)
                            currentItem->setCheckState(Qt::Checked);
                        else
                            currentItem->setCheckState(Qt::Unchecked);
        
                        ui->EntriesTableWidget->setItem( row, 0, currentItem);
                        currentItem->setFlags(currentItem->flags()^(Qt::ItemIsEditable ));
                    }
        

        The problem is that I cannot style the default implementation of the QTableWidgetItem(QCheckbox) that is part of the QTableWidgetItem.

        1 Reply Last reply
        0

        2/3

        5 Aug 2020, 14:50

        • Login

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