当前位置:网站首页>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);
边栏推荐
- Flink production problems (1.10)
- QT using Valgrind to analyze memory leaks
- Epics record reference 5 -- array analog input recordarray analog input (AAI)
- Experience oceanbase database under win10
- Edge loads web pages in IE mode - edge sets ie compatibility
- DAST black box vulnerability scanner part 6: operation (final)
- Discussion on streaming media protocol (MPEG2-TS, RTSP, RTP, RTCP, SDP, RTMP, HLS, HDS, HSS, mpeg-dash)
- Comprehensive application of OpenCV in contour detection and threshold processing
- unity点光源消失
- 双位置继电器XJLS-8G/220
猜你喜欢

How JQ gets the ID name of an element

高翔slam14讲-笔记1

清华大学开源软件镜像站网址

Microservice system design -- distributed transaction service design

躲避小行星游戏

Remapping (STM32)

es6 0622三

什么是BFC?有什么用?

Discussion on streaming media protocol (MPEG2-TS, RTSP, RTP, RTCP, SDP, RTMP, HLS, HDS, HSS, mpeg-dash)

Leetcode99 week race record
随机推荐
py2neo基本语法
Tri rapide (non récursif) et tri de fusion
Leetcode99 week race record
019 basics of C language: C preprocessing
Get system volume across platforms in unity
stm32单片机引脚_如何将单片机的引脚配置为上拉输入
Edge在IE模式下加载网页 - Edge设置IE兼容性
EasyExcel合并相同内容单元格及动态标题功能的实现
Laptop does not have WiFi option solution
Pytest框架的执行规则
Discussion on streaming media protocol (MPEG2-TS, RTSP, RTP, RTCP, SDP, RTMP, HLS, HDS, HSS, mpeg-dash)
Halon common affine transformation operators
Asp. Net core6 websocket simple case
Comprehensive application of OpenCV in contour detection and threshold processing
Zener diode zener diode sod123 package positive and negative distinction
leetcode298周赛记录
Chapter 1 Introduction
Neo4j community conflicts with neo4j desktop
Unity point light disappears
LeetCode-515. 在每个树行中找最大值