当前位置:网站首页>Add widget on qlistwidgetitem
Add widget on qlistwidgetitem
2022-06-27 05:44:00 【opera321】
1、 additional widget No display
These two sentences cannot be reversed :
listWidget>addItem(newItem);
listWidget->setItemWidget(newItem, itemWidget);
2、 additional widget The position has shifted
QListWidget Dynamic increase item Under the way , by item Additional widget A position shift may occur .
The solution is to associate a delegate , This delegate does not need to be attached to widget It matters , Just reload updateEditorGeometry Function .
XItemDelegate.h
#ifndef XITEMDELEGATE_H
#define XITEMDELEGATE_H
#include <QStyledItemDelegate>
class XItemDelegate : public QStyledItemDelegate
{
Q_OBJECT
public:
explicit XItemDelegate(QWidget *parent = nullptr);
virtual void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const;
signals:
public slots:
};
#endif // XITEMDELEGATE_H
XItemDelegate.cpp
#include "XItemDelegate.h"
XItemDelegate::XItemDelegate(QWidget *parent)
{
}
void XItemDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
editor->setGeometry(option.rect);
}
XItemDelegate* itemDelegate = new XItemDelegate();
listWidget->setItemDelegate(itemDelegate);
边栏推荐
- Opencv实现对象跟踪
- Netease cloud music params and encseckey parameter generation code
- Flink生产问题(1.10)
- Some articles about component packaging and my experience
- Junda technology - centralized monitoring scheme for multi brand precision air conditioners
- 关于元器件封装的一些文章和一下我的体会
- [nips 2017] pointnet++: deep feature learning of point set in metric space
- Asp. Net core6 websocket simple case
- 数据库-索引
- 代码即数据
猜你喜欢
Quick sort (non recursive) and merge sort
Remapping (STM32)
函数栈帧的形成与释放
思维的技术:如何破解工作生活中的两难冲突?
Vue学习笔记(五)Vue2页面跳转问题 | vue-router路由概念、分类与使用 | 编程式路由导航 | 路由组件的缓存 | 5种路由导航守卫 | 嵌套路由 | Vue2项目的打包与部署
Leetcode298 weekly race record
【NIPS 2017】PointNet++:度量空间中点集的深层次特征学习
Mechanical transcoding journal [17] template, STL introduction
Two position relay rxmvb2 r251 204 110dc
Terminal in pychar cannot enter the venv environment
随机推荐
C language implementation timer
IP网络通信的单播、组播和广播
C语言实现定时器
STM32关闭PWM输出时,让IO输出固定高或低电平的方法。
树莓派4B上运行opcua协议DEMO接入kubeedge
Using domain name forwarding mqtt protocol, pit avoidance Guide
RTP 发送PS流工具(已经开源)
数据库-索引
导航【机器学习】
Unicast, multicast and broadcast of IP network communication
Qt使用Valgrind分析内存泄漏
Open the door small example to learn ten use case diagrams
Vue学习笔记(五)Vue2页面跳转问题 | vue-router路由概念、分类与使用 | 编程式路由导航 | 路由组件的缓存 | 5种路由导航守卫 | 嵌套路由 | Vue2项目的打包与部署
Navigation [machine learning]
网易云音乐params和encSecKey参数生成代码
AD22 gerber files 点开 gerber steup 界面 有问题 官方解决方法
OpenCV的轮廓检测和阈值处理综合运用
IAR systems fully supports Centrino technology 9 series chips
Codeforces Round #802 (Div. 2)
什么是BFC?有什么用?