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
QtWS25 Last Chance

Custom QCheckbox in QT widgets

Scheduled Pinned Locked Moved Unsolved General and Desktop
qtwidgetsqcheckboxstylesheetqtablewidget
3 Posts 2 Posters 952 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.
  • EagleSparrowE Offline
    EagleSparrowE Offline
    EagleSparrow
    wrote on 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!

    JonBJ 1 Reply Last reply
    0
    • EagleSparrowE EagleSparrow

      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!

      JonBJ Online
      JonBJ Online
      JonB
      wrote on 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
      • EagleSparrowE Offline
        EagleSparrowE Offline
        EagleSparrow
        wrote on 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

        • Login

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