Completer is removed because when you set editable to false the edit line is deleted (and completer with it).
The same happens for validator as both are children of a line edit which gets deleted when you set editable to false.
Yes, I know why it happens, but I don't think it's a normal behavior, so just wanted to point it out, because it looks like a bug.
Stylesheet doesn't work correctly. Here goes a small sample that illustrates the issue. As you can see the background of the combobox should be blue, but it turns white (or default window color on your system) after making it editable. The issue is also caused by line edit deletion and when a new edit is created stylesheet is not applied. If I manually apply stylesheet again it works fine (see the commented line in the code).
#include <QApplication>
#include <QComboBox>
{
Q_OBJECT
public:
{
setStyleSheet("QComboBox { background-color: blue; }");
addItem("item 1");
addItem("item 2");
connect(this, SIGNAL(currentIndexChanged(int)), this, SLOT(handleNewIndex(int)));
}
private slots:
void handleNewIndex(int index)
{
setEditable(index % 2);
// after changing editable state we have to reapply stylesheet
//style()->polish(this);
}
};
int main(int argc, char *argv[])
{
MyComboBox cbox;
cbox.show();
return a.exec();
}
#include "main.moc"
#include <QApplication>
#include <QComboBox>
class MyComboBox: public QComboBox
{
Q_OBJECT
public:
MyComboBox(): QComboBox()
{
setStyleSheet("QComboBox { background-color: blue; }");
addItem("item 1");
addItem("item 2");
connect(this, SIGNAL(currentIndexChanged(int)), this, SLOT(handleNewIndex(int)));
}
private slots:
void handleNewIndex(int index)
{
setEditable(index % 2);
// after changing editable state we have to reapply stylesheet
//style()->polish(this);
}
};
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MyComboBox cbox;
cbox.show();
return a.exec();
}
#include "main.moc"
To copy to clipboard, switch view to plain text mode
Bookmarks