当前位置:网站首页>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);
边栏推荐
- AD22 gerber files 点开 gerber steup 界面 有问题 官方解决方法
- Luogu p2939 [usaco09feb]revamping trails G
- Chapter 1 Introduction
- Leetcode298 weekly race record
- Basic concepts of neo4j graph database
- When STM32 turns off PWM output, it is a method to fix IO output at high or low level.
- [station B up dr_can learning notes] Kalman filter 1
- The most detailed download tutorial of MySQL
- 齐纳二极管 稳压二极管 SOD123封装 正负区分
- DAST black box vulnerability scanner part 6: operation (final)
猜你喜欢

jq怎么获取元素的id名

neo4j图数据库基本概念

论文解读(LG2AR)《Learning Graph Augmentations to Learn Graph Representations》

Codeforces Round #802 (Div. 2)

Terminal in pychar cannot enter the venv environment

How pychart installs packages

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

Codeforces Round #802 (Div. 2)

快速排序(非递归)和归并排序

LeetCode-515. 在每个树行中找最大值
随机推荐
Mechanical transcoding journal [17] template, STL introduction
Netease cloud music params and encseckey parameter generation code
Codeforces Round #802 (Div. 2)
Avoid asteroids
RTP 发送PS流工具(已经开源)
[622. design cycle queue]
Pytest框架的执行规则
[C language] keyword supplement
Web3还没实现,Web5乍然惊现!
neo4j community与neo4j desktop冲突
双位置继电器DLS-34A DC0.5A 220VDC
009 basics of C language: C loop
[station B up dr_can learning notes] Kalman filter 3
Laptop does not have WiFi option solution
[FPGA] design and implementation of frequency division and doubling based on FPGA
leetcode-20. Valid parentheses -js version
022 basics of C language: C memory management and C command line parameters
Halon common affine transformation operators
Edge在IE模式下加载网页 - Edge设置IE兼容性
[station B up dr_can learning notes] Kalman filter 1