向QTreeView列添加填充
我已使用以下QSS代码在QTreeView的标题中添加了左右填充:向QTreeView列添加填充,qt,pyside,Qt,Pyside,我已使用以下QSS代码在QTreeView的标题中添加了左右填充: QHeaderView::section{padding:7px 15px} 但是列的内容不再与标题对齐 如何向列的内容添加15px的填充(如标题中的填充) 编辑:出于某些原因,我使用委托来绘制QTreeView的内容,这就是为什么设置QTreeView::item的样式不起作用(如@svlasov建议的) painter.translate(15,0)似乎可以解决此问题,但当我选择一行时,会出现一种奇怪的效果:选择不是连续
QHeaderView::section{padding:7px 15px}
但是列的内容不再与标题对齐
如何向列的内容添加15px的填充(如标题中的填充)
编辑:出于某些原因,我使用委托来绘制QTreeView
的内容,这就是为什么设置QTreeView::item
的样式不起作用(如@svlasov建议的)
painter.translate(15,0)
似乎可以解决此问题,但当我选择一行时,会出现一种奇怪的效果:选择不是连续的
类似这样的内容:
QTreeView::item { border: 0px; padding: 0 15px; }
这是粗鲁的,但它以一种非常简单的方式满足了3列QTreeWidget的要求
// Okay, I want to make sure my columns are wide enough for the contents, but I also
// Don't want them squished together. So use resizeColumnToContents, to make them
// as small as they can be to show the contents, then take those widths and add some
// spacing and then set the columns to the new widths.
m_tree->resizeColumnToContents (0);
m_tree->resizeColumnToContents (1);
int w0 = m_tree->columnWidth (0) + 20;
int w1 = m_tree->columnWidth (1) + 20;
m_tree->setColumnWidth (0, w0);
m_tree->setColumnWidth (1, w1);
谢谢你的回答,但我做了一个编辑,解释了为什么这对我不起作用。实际上,我只是重新阅读了你的问题,它没有做你想要的,但它做了我来这里时想要的;-)这是不是回应?