In my Qt 5.6.2 project, I noticed that if you double click on a QTreeView
item (the actual arrow part, not the item text) the first click toggles the expanded state, and the second click does nothing.
在我的Qt 5.6.2项目中,我注意到如果你双击QTreeView项目(实际的箭头部分,而不是项目文本),第一次单击切换扩展状态,第二次单击不执行任何操作。
I would instead like the second click to again toggle the expanded state.
我希望再次点击再次切换展开状态。
I tried treeView->setExpandsOnDoubleClick(false);
but the behaviour is still the same since it appears to not affect the arrow part of the item at all. It looks like Qt is deciding for me how the arrow should react to a double click regardless of the property expandsOnDoubleClick
. How can I resolve this?
我试过treeView-> setExpandsOnDoubleClick(false);但行为仍然相同,因为它似乎根本不影响项目的箭头部分。看起来Qt正在决定箭头应该如何对双击做出反应,无论属性expandsOnDoubleClick如何。我该如何解决这个问题?
(Note: this behaviour didn't exist in Qt 5.0.2. Unsure about intermediate Qt versions.)
(注意:Qt 5.0.2中不存在此行为。不确定中间Qt版本。)
1 个解决方案
#1
0
I was able to solve this by subclassing QProxyStyle
and checking for the style hint SH_ListViewExpand_SelectMouseType
and returning a value of 3 instead of the default 2.
我能够通过继承QProxyStyle并检查样式提示SH_ListViewExpand_SelectMouseType并返回值3而不是默认值2来解决这个问题。
class MyProxyStyle : public QProxyStyle
{
public:
int styleHint(StyleHint hint, const QStyleOption *option = 0, const QWidget *widget = 0, QStyleHintReturn *returnData = 0) const
{
if(hint == QStyle::SH_ListViewExpand_SelectMouseType)
return 3;
return QProxyStyle::styleHint(hint, option, widget, returnData);
}
}
#1
0
I was able to solve this by subclassing QProxyStyle
and checking for the style hint SH_ListViewExpand_SelectMouseType
and returning a value of 3 instead of the default 2.
我能够通过继承QProxyStyle并检查样式提示SH_ListViewExpand_SelectMouseType并返回值3而不是默认值2来解决这个问题。
class MyProxyStyle : public QProxyStyle
{
public:
int styleHint(StyleHint hint, const QStyleOption *option = 0, const QWidget *widget = 0, QStyleHintReturn *returnData = 0) const
{
if(hint == QStyle::SH_ListViewExpand_SelectMouseType)
return 3;
return QProxyStyle::styleHint(hint, option, widget, returnData);
}
}