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. QComboBox: Remove checkbox square

QComboBox: Remove checkbox square

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 946 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.
  • A Offline
    A Offline
    anshah
    wrote on last edited by
    #1

    I have a drop down QComboBox that includes a checkbox with a tick mark if it is the selected item. Is there a way to just see the tick mark without the square?

        // Add checkboxes
        QSortFilterProxyModel *pProxy;
        QStandardItemModel    *pSource;
        for (int idx = 0; idx < m_pComboBox->count(); idx++)
        {
            // Add check mark for current 
            pProxy = (QSortFilterProxyModel*) m_pComboBox->model();
            auto const proxyIndex = pProxy->index(idx, 0);
    
            pSource = (QStandardItemModel*) pProxy->sourceModel();
            auto const sourceIndex = pProxy->mapToSource(proxyIndex);
    
            if (idx == m_currSelectedIndex)
            {
                pSource->setData(sourceIndex, Qt::Checked, Qt::CheckStateRole);
            }
            else
            {
                pSource->setData(sourceIndex, Qt::Unchecked, Qt::CheckStateRole);
            }
        }
    

    So basically I just want to see either a tick mark or a blank. Is there a way not to show the checkbox square or make it transparent?

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

      Hi
      You would have to make your self a QStyledItemDelegate
      that can draw them like that.

      Im not aware of any way to style it.

      setStyleSheet("QTableWidget::indicator:checked {background-color:blue;}");
      or
      setStyleSheet("QTableWidget::indicator:checked {background-image:url(:/check-box.png);}"); // replace the actual image

      works for other views but not sure about ComboBox
      Maybe QListView will work. didnt check it.

      1 Reply Last reply
      1

      • Login

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