Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QComboBox: Remove checkbox square



  • 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?


  • Lifetime Qt Champion

    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.


Log in to reply