元素的大小取决于 QListView 的大小

发布于 2024-09-24 22:05:34 字数 112 浏览 1 评论 0原文

我开发了一个绘制列表元素的程序(QListView)。 如何根据 QListView 的大小设置元素的大小? 我在委托中编写了 sizeHint 的实现,但是我不知道从哪里获取实例 QListView 的大小。

I developing a program that draws in elements of the list (QListView).
How do I set the size of an element depending on the size of the QListView?
I write implementation of the sizeHint in the delegate, but where to get the size of the instance QListView I don't know.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ι不睡觉的鱼゛ 2024-10-01 22:05:34

解决方案:

QSize SpinBoxDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex & index) const
{
    QStyleOptionViewItemV4 opt(option);

    qDebug("W = %d\n", opt.widget->width());
    qDebug("H = %d\n", opt.widget->height());
    return QSize(100, 100);
}

Solution:

QSize SpinBoxDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex & index) const
{
    QStyleOptionViewItemV4 opt(option);

    qDebug("W = %d\n", opt.widget->width());
    qDebug("H = %d\n", opt.widget->height());
    return QSize(100, 100);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文