当前位置:网站首页>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);
边栏推荐
- C# netcore中 配置帮助类IConfiguration
- 【合辑】点云基础知识及点云催化剂软件功能介绍
- Implementation of easyexcel's function of merging cells with the same content and dynamic title
- 项目-h5列表跳转详情,实现后退不刷新,修改数据则刷新的功能(记录滚动条)
- stm32单片机引脚_如何将单片机的引脚配置为上拉输入
- 双位置继电器XJLS-8G/220
- EasyExcel合并相同内容单元格及动态标题功能的实现
- 洛谷P2939 [USACO09FEB]Revamping Trails G 题解
- Leetcode298 weekly race record
- Terminal in pychar cannot enter the venv environment
猜你喜欢

Some articles about component packaging and my experience

高翔slam14讲-笔记1

【FPGA】基于bt1120时序设计实现棋盘格横纵向灰阶图数据输出

Basic concepts of neo4j graph database

Ad22 Gerber files Click to open the Gerber step interface. Official solutions to problems

函数栈帧的形成与释放

stm32读取IO高低电平状态

Asp.Net Core6 WebSocket 简单案例
![[622. design cycle queue]](/img/f2/d499ac9ddc50b73f8c83e8b6af2483.png)
[622. design cycle queue]

竣达技术丨多品牌精密空调集中监控方案
随机推荐
面试:Selenium 中有哪几种定位方式?你最常用的是哪一种?
Interview: what are the positioning methods in selenium? Which one do you use most?
Navigation [machine learning]
WebRTC系列-網絡傳輸之7-ICE補充之提名(nomination)與ICE_Model
DAST 黑盒漏洞扫描器 第六篇:运营篇(终)
Neo4j community conflicts with neo4j desktop
Senior [Software Test Engineer] learning route and necessary knowledge points
LeetCode-515. 在每个树行中找最大值
微信小程序WebSocket使用案例
Redis4.0新特性-主动内存碎片整理
Reading graph augmentations to learn graph representations (lg2ar)
Asp. Net core6 websocket simple case
Flink production problems (1.10)
mysql 查询时将状态改为相对应的文字
EasyExcel合并相同内容单元格及动态标题功能的实现
双位置继电器XJLS-8G/220
树莓派4B上运行opcua协议DEMO接入kubeedge
重映像(STM32)
论文解读(LG2AR)《Learning Graph Augmentations to Learn Graph Representations》
Codeforces Round #802 (Div. 2)