gpt4 book ai didi

c++ - QListView 高度根据内容

转载 作者:太空狗 更新时间:2023-10-29 21:29:02 27 4
gpt4 key购买 nike

我有一个带有字符串列表的 QListView。

基本上,我将它用作自动完成过程的 QLineEdit 的弹出窗口。我不希望 QListView 显示空白行,只显示其中包含字符串的行。看到这个: Image

我希望它自动调整自己的大小,这样在最后一个条目之后就不会有这些空白行了。<​​/p>

谢谢

最佳答案

您可以尝试这样做:重新实现 QListView::rowsInserted()方法类。假设您从 QListView 继承了 MyListView。所以代码看起来像这样:

void MyListView::rowsInserted ( const QModelIndex & parent, int start, int end )
{
QListView::rowsInserted(parent, start, end);
int rc = model()->rowCount();

// use this all the rows have the same height. otherwise
// you will need to iterate and sum all row heights
resize(width(), rc ? rc*sizeHintForRow(0): height());
}

但为了更简单,我建议您使用 QCompleterwith QLineEdit .它已经为您的需要而设计,您无需花时间尝试让它发挥作用。

关于c++ - QListView 高度根据内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5721692/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com