• 7473阅读
  • 11回复

在做一个网络程序时需要这种界面,用QTreeWidget怎么设计? [复制链接]

上一主题 下一主题
离线蠢蠢欲懂
 
只看楼主 倒序阅读 楼主  发表于: 2012-05-02

我想做一个如上图所示的界面,用QTreeWidget做。其中涉及到位编辑(即一个字节中的某一位或者某几位需要编辑,例如下图所展示的分别是 编辑 第4位,第5和第6位,第2位和3位和4位)第三列该怎么实现呢?只有文本,可是第三列好像不是对齐的,QTreeWidget可以单独控制列吗?

下面是一个完全的图:



离线蠢蠢欲懂
只看该作者 1楼 发表于: 2012-05-02
给自己顶一下下
离线蠢蠢欲懂
只看该作者 2楼 发表于: 2012-05-02
欢迎 交流、讨论、教导
离线passion_wu
只看该作者 3楼 发表于: 2012-05-02
我的第一感觉是为QTreeView设置delegate,然后重写delegate的paint函数可以实现。
这个比较复杂,估计你得参照Qt绘制Item的源代码。
离线蠢蠢欲懂
只看该作者 4楼 发表于: 2012-05-02
回 3楼(passion_wu) 的帖子
用QTreeWidget不行吗?我看了QTreeWidget的文档:

void QTreeWidget::setItemWidget ( QTreeWidgetItem * item, int column, QWidget * widget )
Sets the given widget to be displayed in the cell specified by the given item and column.
The given widget's autoFillBackground property must be set to true, otherwise the widget's background will be transparent, showing both the model data and the tree widget item.
This function should only be used to display static content in the place of a tree widget item. If you want to display custom dynamic content or implement a custom editor widget, use QTreeView and subclass QItemDelegate instead.
This function cannot be called before the item hierarchy has been set up, i.e., the QTreeWidgetItem that will hold widget must have been added to the view before widget is set.
Note: The tree takes ownership of the widget.
This function was introduced in Qt 4.1.
See also itemWidget() and Delegate Classes.
他说,这样设置的只是静态的内容,如果要动态编辑就用QTreeView,留下个QQ详聊吧哥们,我的 983970335
离线godvmxi

只看该作者 5楼 发表于: 2012-05-02
回 3楼(passion_wu) 的帖子
同意,顶三楼的javascript:void(0)javascript:void(0)javascript:void(0)
离线蠢蠢欲懂
只看该作者 6楼 发表于: 2012-05-02
离线淳于半邪

只看该作者 7楼 发表于: 2012-05-02
你要在item上设置某些位可编辑,某些位不可编辑;只能重写item类

还有你说什么单独控制列,这个很多函数中的参数column就是设置某列的
离线蠢蠢欲懂
只看该作者 8楼 发表于: 2012-05-03
回 3楼(passion_wu) 的帖子
delegate设置之后, 每个Item都是一样的delegate,而我需要的是不一样的啊,比如每个 QLineEdit的validator就不一样
离线fish0619

只看该作者 9楼 发表于: 2012-05-03
组合使用`QAbstractItemModel`和`QAbstractItemDelegate`。可以为每个item定制widget.
离线passion_wu
只看该作者 10楼 发表于: 2012-05-03
回 8楼(蠢蠢欲懂) 的帖子
delegate设置之后, 每个Item都是一样的delegate,  这个说法是错误的,你看看delegate的
creatorEditor函数,它不是有个index参数么???
离线蠢蠢欲懂
只看该作者 11楼 发表于: 2012-05-03
回 9楼(fish0619) 的帖子
谢谢各位了,我正在研究,等研究好了,和各位讨论,分享
快速回复
限100 字节
 
上一个 下一个