QTreeView未显示标题
QTreeView not showing header
我正在显示一个TreeView,其中包含一个自定义sortfilterfroxymodel(以另一个自定义模型为源)和一个自定义委托(覆盖的绘画),以影响每个项目的显示。
但是,我无法显示TreeView的标题。我查看了代理和普通模型,它们都调用了headerData()并返回了正确的值。我没有明确隐藏标题。事实上,我显式地显示了TreeView的标头(),并将HeaderHidden()设置为false。
是什么原因导致收割台未显示?
这是委托的paint()函数,我怀疑这是错误的:
//---------------------------------------------------------------------------------
void
MyDelegate::paint(QPainter* p_painter, const QStyleOptionViewItem& p_option, const QModelIndex& p_index) const
{
// Get a custom text
QString text = "";
// Code that changes the text variable, nothing fancy, no pre-mature return
// Left out for convenience
// Call painter methods for drawing
p_painter->save();
p_painter->setClipRect(p_option.rect);
drawBackground(p_painter, p_option, p_index);
drawDisplay(p_painter, p_option, p_option.rect, text);
drawFocus(p_painter, p_option, p_option.rect);
p_painter->restore();
}
如果你想知道为什么我要手动执行所有的绘制程序(save()、drawBackground等),那是因为这似乎是更改paint()函数中显示文本的唯一方法。至少是我唯一能搞清楚的。但我不知道这是否与视图中没有显示标题有关。
编辑:到目前为止,我试图用默认的油漆替换我自己的油漆。标头仍然没有显示,因此paint()方法似乎是无辜的;)
问题是我"忘记"在headerData()函数的开头添加以下内容:
if (role != Qt::DisplayRole)
return QVariant();
尽管我不得不说,为了显示任何东西,你必须有这些行,这有点奇怪。如果像这样需要它们,为什么不在调用headerData()之前进行检查呢?
无论如何,我希望这可能会帮助一些有同样问题的人:)
相关文章:
- 比较并显示使用最小值(a,b)和最大值(a、b)升序排列的4个数字
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 字符串-C++后显示的随机字符
- Gtkmm 窗口为空白,不显示任何小部件或标题
- 无法在 GLFW 窗口标题中显示'ä'
- 当鼠标悬停在 MFC C++ 中列表控件的列标题上时,可视显示工具提示
- 在 MFC C++中悬停列表控件的列标题的可视化显示工具提示
- 我的QT程序显示带有标题的空白窗口
- 无法设置和显示 QTabelView 水平标题
- 如何在RPi3上的交叉编译应用程序的主窗口上显示边框和标题栏
- QTreeView未显示标题
- c++builder-显示没有标题的字节数组颜色信息
- QTableView 显示列标题,但不显示数据
- 在窗口标题和消息框中显示错误的语言:win32应用程序,opengl
- 在GLFW窗口标题中显示FPS
- Opencv C++;在标题中使用int显示多个图像
- 为什么我的视图不显示标题?
- 标题名称不显示,背景颜色不改变
- 使控制台标题栏显示变量的值
- 电子邮件标题显示,dkim=硬失败(测试模式)和dkim=永久错误(坏信号)