How to refresh QComboBox?
-
@Pl45m4 I tried many things:
view(), view()->viewport(), this: update / repaint in many combinations. And no good result...EDIT:
I find the same problem here:And... with no solution
-
-
After add new item to comboBox I have to use showPopup() method. But when I have only this one function in my timer slot, popup will be shown when popup is hidden and when is visible. I don't want situation that I click somewhere in button to add new item to comboBox, this comboBox will be hidden and poof... now is visible :D
So I have to check state - view()->isVisible.
And now is ok. When I add new Item and popup is hidden - it will be hidden. When I add new item and popup is visible - I add new item and popup will be visible. Perfect.
But I have 2 other problems:
-
Sometimes when I click many times on arrow in QComboBox I still see that ScrollBar ( and I don't talk about maxVisibleItems problem ). I solve ( I think I solve ) problem override paint() function and in this function I check visibility of verticalScrollBar. When it is visible = showPopup().
-
Sometimes when I have visible popup and change focus on other app ( for example qt creator ) I still see popup ( only popup - no app, no comboBox ) - picture to this situation is above in 2 places.
I think when I click on other app (in this example qtCreator ) ) to hide popup, in my timer slot at the same moment I check visible of popup. It is in state "now I'm in process 'during hide popup' ". So popup is hide in 50%, but the state is still visible :D And popup is shown without my app. So my condition
view()->isVisible() ?
is not good.
EDIT:
My code is something like ( maybe be wrong, because I'm in other computer, so please treat this code like pseudocode ):
#include "mycombobox.h" #include <QTimer> #include <QAbstractItemView> #include <QScrollBar> myComboBox::myComboBox(QWidget *parent): QComboBox(parent) { QTimer *timer = new QTimer; connect(timer, &QTimer::timeout, this, &myComboBox::timeoutSlot); timer->start(1000); setMaxVisibleItems(40); } void myComboBox::timeoutSlot() { addItem("randomText"); if(view()->isVisible()) { showPopup(); } } void myComboBox::paint(QPaintEvent *ev) { QComboBox::paint(ev); if(view()->verticalScrollBar()->isVisible()) { showPopup(); } }
-
-
@TomNow99 said in How to refresh QComboBox?:
When the QCombobox's popup is visible and I add new Item in that moment I see that item in comboBox, but I can select it only using scrollBar.
See https://bugreports.qt.io/browse/QTBUG-39420 - feel free to provide a patch :)