我想在QTableView
中获得一个单元格/行,如下所示:
运行Ubuntu时,QStyledItemDelegate
同时适用于QTreeView
和QTableView
,但在Windows上,它只适用于QTreeView
,而且只有在我不重新实现paint
方法的情况下。在
所以我的两个问题是:
如何使QStyledItemDelegate
看起来像QTableView
中的上图?在
当重新实现paint
时,如何使QStyledItemDelegate
看起来像上图?在
文本旁边的图像是不需要的。我只是在寻找风格悬停和选择框。 为了以防万一,我的Qt版本是4.7.2。在
我终于想够了。在
我没有解决的是,为什么不重写
QStyledItemDelegate.paint()
与重写它有不同的效果,比如:但这不是我问题的一部分。
我所解决的问题是如何在手工绘制时获得原始外观。以前,在绘制项目时,我使用: ^{pr2}$
有一个问题就是没有画出本土的焦点或选择。我看了
QApplication.style().drawControl()
的方法签名:注意到
widget
参数,并尝试传入一个QTreeView
。成功了。传递的QTreeView
并不重要,但它使视图以本机方式呈现。在因此,最终,呈现本机
QTableView
与调用以下命令一样简单:在
QStyledItemDelegate
的绘制方法中。在我在qtcentre上打开了一个帖子,要求做同样的事情。回答我的人给我提供了一个C++代码示例和一个显示结果的图片。它似乎在C++中工作得很好,但在PySee中却不好(不知道PYQT),所以它可能是一个bug。在
工作代码如下:
相关问题 更多 >
编程相关推荐