Unsolved Hide QCombobox item correctly and not ruin the view
There is a solution to use setRowHidden function from QListView like:
qobject_cast<QListView *>(combobox->view())->setRowHidden(0, true);
This certainly does the job, but I found an issue with this solution. A combobox normally will automatically adjust its pop-up view downwards/upwards based on its visibility. However, once the setRowHidden is called, it will no longer do that. It becomes a small dropdown list with scrollbar showing only two items at a time.
How to fix this? Or is the default combobox view is not simply a QListView?
Which version of Qt is it ?
On which platform ?
Can you provide a minimal compilable example that shows this behaviour ?
Did you try to use QSortFilterProxyModel between the QComboBox view and model ?
I'm with Qt5.14.2 in Windows. The "fusion" style in Linux won't have this issue but it has the same issue with both Windows and Windows Vista style.
An simple example is like following:
auto combobox = new QCombobox(this); combobox->addItem("1min"); combobox->addItem("2mins"); combobox->addItem("3mins"); ... combobox->addItem("All"); qobject_cast<QListView *>(combobox->view())->setRowHidden(0, true); qobject_cast<QListView *>(combobox->view())->setRowHidden(1, true); qobject_cast<QListView *>(combobox->view())->setRowHidden(2, true);
Then the combobox won't auto-adjust anymore to go upwards nor showing more contents as the normal combobox would. See below:
If I remove those lines with setRowHidden(), it will work as usual. See below:
I felt this function somehow changes some settings in the backend of the combobox implementation or the view behaviour.
And if you force the fusion style on Windows ?
@SGaist If forcing fusion style, it'll show the full list. But the style itself is very different. Fusion style has tick boxes and shows everything with no scrollbar I think.