当前位置:网站首页>QListWidgetItem上附加widget
QListWidgetItem上附加widget
2022-06-27 05:33:00 【opera321】
1、附加widget不显示
这两句不能颠倒:
listWidget>addItem(newItem);
listWidget->setItemWidget(newItem, itemWidget);
2、附加widget位置发生偏移
QListWidget在动态增加item的方式下,为item附加的widget可能会发生位置偏移。
解决方法是关联一个委托,这个委托并不需要和附加widget有关系,只需要重载updateEditorGeometry函数即可。
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);
边栏推荐
- neo4j图数据库基本概念
- 012 C language foundation: C array
- 微信小程序WebSocket使用案例
- Flink production problems (1.10)
- Edge loads web pages in IE mode - edge sets ie compatibility
- LeetCode-515. Find the maximum value in each tree row
- Asp.Net Core6 WebSocket 简单案例
- 论文解读(LG2AR)《Learning Graph Augmentations to Learn Graph Representations》
- AD22 gerber files 点开 gerber steup 界面 有问题 官方解决方法
- NEON优化1:软件性能优化、降功耗怎么搞?
猜你喜欢

RTP 发送PS流工具(已经开源)

齐纳二极管 稳压二极管 SOD123封装 正负区分

【FPGA】 基于FPGA分频,倍频设计实现

Microservice system design -- unified authentication service design

Remapping (STM32)

How JQ gets the reciprocal elements

jq怎么获取倒数的元素

Niuke practice 101-c reasoning clown - bit operation + thinking

Double position relay rxmd2-1mrk001984 dc220v
![[station B up dr_can learning notes] Kalman filter 1](/img/18/ee21d31f6a118e4e4ad466b55361cc.gif)
[station B up dr_can learning notes] Kalman filter 1
随机推荐
stm32读取IO高低电平状态
关于元器件封装的一些文章和一下我的体会
Web3 has not been implemented yet, web5 suddenly appears!
Common programming abbreviations for orbit attitude
[station B up dr_can learning notes] Kalman filter 1
流媒体协议初探(MPEG2-TS、RTSP、RTP、RTCP、SDP、RTMP、HLS、HDS、HSS、MPEG-DASH)
Two position relay hjws-9440
洛谷P2939 [USACO09FEB]Revamping Trails G 题解
[622. design cycle queue]
neo4j数据库导出
论文解读(LG2AR)《Learning Graph Augmentations to Learn Graph Representations》
【NIPS 2017】PointNet++:度量空间中点集的深层次特征学习
Flink production problems (1.10)
Execution rules of pytest framework
Microservice system design -- microservice monitoring and system resource monitoring design
重映像(STM32)
AD22 gerber files 点开 gerber steup 界面 有问题 官方解决方法
006 C language foundation: C storage class
STM32 MCU pin_ How to configure the pin of single chip microcomputer as pull-up input
OpenCV的轮廓检测和阈值处理综合运用