• 11436阅读
  • 10回复

请问怎样把QTreeView里面选中行的图标也能选中啊? [复制链接]

上一主题 下一主题
离线lovehouye
 

只看楼主 倒序阅读 楼主  发表于: 2011-07-05
要做成如图的效果,选中某一行之后,连着那个图标 + 也选中了。
这个是Qt 的Demo里面给的图片,但是不是在Windows 下的效果。
我也试过了用 show-decoration-selected: 1; 但还是不行。请各位帮忙看看,先谢了。



离线alexltr

只看该作者 1楼 发表于: 2011-07-05
allColumnsShowFocus : boolThis property holds whether items should show keyboard focus using all columns.

If this property is true all columns will show focus, otherwise only one column will show focus.

The default is false.

This property was introduced in Qt 4.2.

Access functions:

bool  allColumnsShowFocus () const
void  setAllColumnsShowFocus ( bool enable )
我不从事IT,只是喜欢Qt。
我不是程序员,只是与程序有缘。
我写程序,只是为了让工作变得简单有序!

                      ----  一个一直在入门的编程学习者
离线lovehouye

只看该作者 2楼 发表于: 2011-07-05
引用第1楼alexltr于2011-07-05 10:51发表的  :
allColumnsShowFocus : boolThis property holds whether items should show keyboard focus using all columns.
If this property is true all columns will show focus, otherwise only one column will show focus.
The default is false.
.......

Thanks. But it seems still not work. Only a dotted border has been shown.
离线alexltr

只看该作者 3楼 发表于: 2011-07-05
i tried already this function the day before yesterday. it did work.
i am using Win 7 + Qt4.7
我不从事IT,只是喜欢Qt。
我不是程序员,只是与程序有缘。
我写程序,只是为了让工作变得简单有序!

                      ----  一个一直在入门的编程学习者
离线lovehouye

只看该作者 4楼 发表于: 2011-07-05
引用第3楼alexltr于2011-07-05 11:31发表的  :
i tried already this function the day before yesterday. it did work.
i am using Win 7 + Qt4.7


I have tried many times in Windows XP 32 SP3.
But I just get it like this. Do you have some special settings?


离线XChinux

只看该作者 5楼 发表于: 2011-07-05
通过设置Qt Style Sheet可以实现这种效果的。
多摸索一下。

二笔 openSUSE Vim N9 BB10 XChinux@163.com 网易博客 腾讯微博
承接C++/Qt、Qt UI界面、PHP及预算报销系统开发业务
离线alexltr

只看该作者 6楼 发表于: 2011-07-05
Sorry, 是我记错了。下班回来试了,前面的图标是没有highlighted的。

I saw the thread you posted on qtcentre, ha ha. good luck.
我不从事IT,只是喜欢Qt。
我不是程序员,只是与程序有缘。
我写程序,只是为了让工作变得简单有序!

                      ----  一个一直在入门的编程学习者
离线alexltr

只看该作者 7楼 发表于: 2011-07-05
回 4楼(lovehouye) 的帖子
你所讲的Demo图片上的例子是用plastique样式实现的。

你可以用下面的代码实现:
QApplication::setStyle(QStyleFactory::create("plastique"));

如果其它部件你不想用这种style,我觉得你可以参考一下qt的源代码看plastique样式是怎样实现的。
我不从事IT,只是喜欢Qt。
我不是程序员,只是与程序有缘。
我写程序,只是为了让工作变得简单有序!

                      ----  一个一直在入门的编程学习者
离线lovehouye

只看该作者 8楼 发表于: 2011-07-06
回 7楼(alexltr) 的帖子
Thanks for your investigation and help.
I will check the Qt source code about this, hope can find some useful message.
离线lovehouye

只看该作者 9楼 发表于: 2011-07-08
问题解决了,在delegate 里面,paint 方法,
    if( option.state & QStyle::State_Selected )
    {

        QRect rect( option.rect );
        rect.setLeft( 0 );
        painter->fillRect( rect, option.palette.highlight() );
    }
但是这样有个问题,会把 图标给覆盖掉,所以需要在这个方法后面,重绘一下图标(+)或者其他图标。
弄了好久,还是不完美,不过列出来给大家分享讨论一下,希望大家能够分享有更好的方法。
离线蠢蠢欲懂
只看该作者 10楼 发表于: 2012-05-07
顶 顶顶
快速回复
限100 字节
 
上一个 下一个