当前位置:网站首页>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);
边栏推荐
- 018 basics of C language: C file reading and writing
- Gao Xiang slam14 lecture - note 1
- Cognition - how to fill in 2022 college entrance examination volunteers
- [FPGA] realize the data output of checkerboard horizontal and vertical gray scale diagram based on bt1120 timing design
- Luogu p2939 [usaco09feb]revamping trails G
- 《数据库原理与应用》第一版 马春梅……编著 期末复习笔记
- Reading graph augmentations to learn graph representations (lg2ar)
- Dual position relay dls-34a dc0.5a 220VDC
- Unity中跨平台获取系统音量
- [unity] button of UI interactive component & summary of optional base classes
猜你喜欢
![Mechanical transcoding journal [17] template, STL introduction](/img/78/926db660139fda3d31cceccad7096c.png)
Mechanical transcoding journal [17] template, STL introduction

ES6 0622 III

LeetCode-515. Find the maximum value in each tree row

导航【机器学习】

Cognition - how to fill in 2022 college entrance examination volunteers

体验 win10 下 oceanbase 数据库

es6 0622三

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

LeetCode-515. 在每个树行中找最大值

stm32读取IO高低电平状态
随机推荐
Interview: what are the positioning methods in selenium? Which one do you use most?
Execution rules of pytest framework
Acwing's 57th weekly match -- BC question is very good
How JQ gets the ID name of an element
DAST 黑盒漏洞扫描器 第六篇:运营篇(终)
EPICS记录参考5 -- 数组模拟输入记录Array Analog Input (aai)
双位置继电器JDP-1440/DC110V
stm32单片机引脚_如何将单片机的引脚配置为上拉输入
C语言实现定时器
008 C language foundation: C judgment
【622. 设计循环队列】
Web3 has not been implemented yet, web5 suddenly appears!
Laptop does not have WiFi option solution
双位置继电器HJWS-9440
neo4j图数据库基本概念
RTP sending PS stream tool (open source)
Some articles about component packaging and my experience
Wechat applet websocket use case
Qt使用Valgrind分析内存泄漏
jq怎么获取倒数的元素