qss 怎么设置 qcombobox 的 popup位置
时间: 2023-04-06 13:03:52 浏览: 102
你可以使用 QComboBox 的 setView方法来设置弹出窗口的位置。例如,使用 setView(new QListView()) 来将弹出窗口设置为 QListView,然后使用 setGeometry() 方法来设置弹出窗口的位置。
相关问题
qcombobox popup设置border-radius
QComboBox的下拉框样式设置border-radius属性后出现黑色边角是因为QComboBox的view窗口属性干扰导致的。为了解决这个问题,你需要设置view窗口的属性以使样式生效。你可以使用以下代码进行设置:
```cpp
ui->comboBox_rand->view()->window()->setWindowFlags(Qt::Popup|Qt::FramelessWindowHint|Qt::NoDropShadowWindowHint);
ui->comboBox_rand->view()->window()->setAttribute(Qt::WA_TranslucentBackground);
```
此外,如果你想要给下拉框添加边缘阴影效果,你可以使用以下代码:
```cpp
QGraphicsDropShadowEffect *shadowRand = new QGraphicsDropShadowEffect(this);
shadowRand->setOffset(0, 0);
shadowRand->setColor(QColor("#444444"));
shadowRand->setBlurRadius(15);
ui->comboBox_rand->view()->setGraphicsEffect(shadowRand);
```
你可以参考这篇博客文章了解更多关于QComboBox样式的信息:https://www.cnblogs.com/csuftzzk/p/qss_combobox.html
另外,如果你想要实现QCompleter的自动补全下拉列表样式,你可以通过completer->popup()进行设置。具体代码参考以下示例:
```cpp
Widget::Widget(QWidget *parent) : QWidget(parent) {
word_list << "Java" << "C" << "C#" << "PHP" << "Perl" << "Python" << "Delphi" << "Ruby";
search_line_edit = new QLineEdit(this);
completer = new QCompleter(this);
string_list_model = new QStringListModel(word_list, this);
completer->setCaseSensitivity(Qt::CaseInsensitive);
completer->setModel(string_list_model);
search_line_edit->setCompleter(completer);
connect(search_line_edit, SIGNAL(editingFinished()), this, SLOT(editComplete()));
}
void Widget::editComplete() {
QString text = search_line_edit->text();
if (QString::compare(text, QString("")) != 0) {
bool is_contains = word_list.contains(text, Qt::CaseInsensitive);
if (!is_contains) {
word_list << text;
string_list_model->setStringList(word_list);
//completer->setModel(new QStringListModel(wordList, this));
}
}
}
```
qss怎么设置qcombobox的下拉框
可以使用QSS设置QComboBox的下拉框,例如:
QComboBox::drop-down {
border: none;
background: transparent;
image: url(:/images/arrow_down.png);
}
其中,QComboBox::drop-down表示下拉框的样式,border:none表示去掉边框,background:transparent表示背景透明,image:url(:/images/arrow_down.png)表示下拉箭头的图片路径。你也可以根据自己的需要进行调整。