Detecting clicks on QTreeView icons
up vote
0
down vote
favorite
I have a QTreeView in which some items are decorated with an icon. The items could be in any column of the TreeView.
I wish to know how to detect mouse clicks on an icon. I can use the view's mousePressEvent() to detect a mouse press, I can check whether an icon is present in the clicked item by calling the model's data() method with Qt.DecorationRole to see whether I get an empty QVariant back, and I can query the size of the icon using the view's iconSize() method. But I have no way of knowing the co-ordinates of the icon within the item's visual rectangle.
PS. Other SO questions relating to QTreeView decorations usually refer to the tree collapse and expand icons, and have no bearing on this question.
python qt pyqt qtreeview
|
show 2 more comments
up vote
0
down vote
favorite
I have a QTreeView in which some items are decorated with an icon. The items could be in any column of the TreeView.
I wish to know how to detect mouse clicks on an icon. I can use the view's mousePressEvent() to detect a mouse press, I can check whether an icon is present in the clicked item by calling the model's data() method with Qt.DecorationRole to see whether I get an empty QVariant back, and I can query the size of the icon using the view's iconSize() method. But I have no way of knowing the co-ordinates of the icon within the item's visual rectangle.
PS. Other SO questions relating to QTreeView decorations usually refer to the tree collapse and expand icons, and have no bearing on this question.
python qt pyqt qtreeview
From what I understand you want to detect if you press an icon of some item in the QTreeView, let's say that this information is detected: what information do you want to obtain, do you want to obtain the QModelIndex or perform some action ?, on the other hand the second part of your question does not I extend it, could you explain me.
– eyllanesc
Nov 22 at 9:25
On the other hand, why the need to detect that click ?, the position of the icon depends on the QStyle that is very dependent on the OS so probably there is no answer, maybe you have an XY problem and then we can give you another alternative.
– eyllanesc
Nov 22 at 9:27
The problem is to detect the mouse click - in my case I will be performing an action depending on the data in the model, but that is irrelevant to the issue. The second part is related because the position of the icon within an item is controlled by its styling - but I see your point that it adds nothing to the question, so I will remove it. Thanks.
– mkam
Nov 22 at 9:30
As indicated, I think there is no solution since the position of the icon is very dependent on QStyle, for example if we check the paint method of the QStyledItemDelegate we see that the painted code.qt.io/cgit/qt/qtbase.git/tree/src/widgets/itemviews/… :style->drawControl(QStyle::CE_ItemViewItem, &opt, painter, widget)
– eyllanesc
Nov 22 at 9:33
and many times the QStyle introduce numerical values to convenience that are not standard to give it a different style and that is easily if you execute your code in several OS, or use a different QStyle.
– eyllanesc
Nov 22 at 9:35
|
show 2 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a QTreeView in which some items are decorated with an icon. The items could be in any column of the TreeView.
I wish to know how to detect mouse clicks on an icon. I can use the view's mousePressEvent() to detect a mouse press, I can check whether an icon is present in the clicked item by calling the model's data() method with Qt.DecorationRole to see whether I get an empty QVariant back, and I can query the size of the icon using the view's iconSize() method. But I have no way of knowing the co-ordinates of the icon within the item's visual rectangle.
PS. Other SO questions relating to QTreeView decorations usually refer to the tree collapse and expand icons, and have no bearing on this question.
python qt pyqt qtreeview
I have a QTreeView in which some items are decorated with an icon. The items could be in any column of the TreeView.
I wish to know how to detect mouse clicks on an icon. I can use the view's mousePressEvent() to detect a mouse press, I can check whether an icon is present in the clicked item by calling the model's data() method with Qt.DecorationRole to see whether I get an empty QVariant back, and I can query the size of the icon using the view's iconSize() method. But I have no way of knowing the co-ordinates of the icon within the item's visual rectangle.
PS. Other SO questions relating to QTreeView decorations usually refer to the tree collapse and expand icons, and have no bearing on this question.
python qt pyqt qtreeview
python qt pyqt qtreeview
edited Nov 22 at 9:30
asked Nov 22 at 9:19
mkam
238110
238110
From what I understand you want to detect if you press an icon of some item in the QTreeView, let's say that this information is detected: what information do you want to obtain, do you want to obtain the QModelIndex or perform some action ?, on the other hand the second part of your question does not I extend it, could you explain me.
– eyllanesc
Nov 22 at 9:25
On the other hand, why the need to detect that click ?, the position of the icon depends on the QStyle that is very dependent on the OS so probably there is no answer, maybe you have an XY problem and then we can give you another alternative.
– eyllanesc
Nov 22 at 9:27
The problem is to detect the mouse click - in my case I will be performing an action depending on the data in the model, but that is irrelevant to the issue. The second part is related because the position of the icon within an item is controlled by its styling - but I see your point that it adds nothing to the question, so I will remove it. Thanks.
– mkam
Nov 22 at 9:30
As indicated, I think there is no solution since the position of the icon is very dependent on QStyle, for example if we check the paint method of the QStyledItemDelegate we see that the painted code.qt.io/cgit/qt/qtbase.git/tree/src/widgets/itemviews/… :style->drawControl(QStyle::CE_ItemViewItem, &opt, painter, widget)
– eyllanesc
Nov 22 at 9:33
and many times the QStyle introduce numerical values to convenience that are not standard to give it a different style and that is easily if you execute your code in several OS, or use a different QStyle.
– eyllanesc
Nov 22 at 9:35
|
show 2 more comments
From what I understand you want to detect if you press an icon of some item in the QTreeView, let's say that this information is detected: what information do you want to obtain, do you want to obtain the QModelIndex or perform some action ?, on the other hand the second part of your question does not I extend it, could you explain me.
– eyllanesc
Nov 22 at 9:25
On the other hand, why the need to detect that click ?, the position of the icon depends on the QStyle that is very dependent on the OS so probably there is no answer, maybe you have an XY problem and then we can give you another alternative.
– eyllanesc
Nov 22 at 9:27
The problem is to detect the mouse click - in my case I will be performing an action depending on the data in the model, but that is irrelevant to the issue. The second part is related because the position of the icon within an item is controlled by its styling - but I see your point that it adds nothing to the question, so I will remove it. Thanks.
– mkam
Nov 22 at 9:30
As indicated, I think there is no solution since the position of the icon is very dependent on QStyle, for example if we check the paint method of the QStyledItemDelegate we see that the painted code.qt.io/cgit/qt/qtbase.git/tree/src/widgets/itemviews/… :style->drawControl(QStyle::CE_ItemViewItem, &opt, painter, widget)
– eyllanesc
Nov 22 at 9:33
and many times the QStyle introduce numerical values to convenience that are not standard to give it a different style and that is easily if you execute your code in several OS, or use a different QStyle.
– eyllanesc
Nov 22 at 9:35
From what I understand you want to detect if you press an icon of some item in the QTreeView, let's say that this information is detected: what information do you want to obtain, do you want to obtain the QModelIndex or perform some action ?, on the other hand the second part of your question does not I extend it, could you explain me.
– eyllanesc
Nov 22 at 9:25
From what I understand you want to detect if you press an icon of some item in the QTreeView, let's say that this information is detected: what information do you want to obtain, do you want to obtain the QModelIndex or perform some action ?, on the other hand the second part of your question does not I extend it, could you explain me.
– eyllanesc
Nov 22 at 9:25
On the other hand, why the need to detect that click ?, the position of the icon depends on the QStyle that is very dependent on the OS so probably there is no answer, maybe you have an XY problem and then we can give you another alternative.
– eyllanesc
Nov 22 at 9:27
On the other hand, why the need to detect that click ?, the position of the icon depends on the QStyle that is very dependent on the OS so probably there is no answer, maybe you have an XY problem and then we can give you another alternative.
– eyllanesc
Nov 22 at 9:27
The problem is to detect the mouse click - in my case I will be performing an action depending on the data in the model, but that is irrelevant to the issue. The second part is related because the position of the icon within an item is controlled by its styling - but I see your point that it adds nothing to the question, so I will remove it. Thanks.
– mkam
Nov 22 at 9:30
The problem is to detect the mouse click - in my case I will be performing an action depending on the data in the model, but that is irrelevant to the issue. The second part is related because the position of the icon within an item is controlled by its styling - but I see your point that it adds nothing to the question, so I will remove it. Thanks.
– mkam
Nov 22 at 9:30
As indicated, I think there is no solution since the position of the icon is very dependent on QStyle, for example if we check the paint method of the QStyledItemDelegate we see that the painted code.qt.io/cgit/qt/qtbase.git/tree/src/widgets/itemviews/… :
style->drawControl(QStyle::CE_ItemViewItem, &opt, painter, widget)
– eyllanesc
Nov 22 at 9:33
As indicated, I think there is no solution since the position of the icon is very dependent on QStyle, for example if we check the paint method of the QStyledItemDelegate we see that the painted code.qt.io/cgit/qt/qtbase.git/tree/src/widgets/itemviews/… :
style->drawControl(QStyle::CE_ItemViewItem, &opt, painter, widget)
– eyllanesc
Nov 22 at 9:33
and many times the QStyle introduce numerical values to convenience that are not standard to give it a different style and that is easily if you execute your code in several OS, or use a different QStyle.
– eyllanesc
Nov 22 at 9:35
and many times the QStyle introduce numerical values to convenience that are not standard to give it a different style and that is easily if you execute your code in several OS, or use a different QStyle.
– eyllanesc
Nov 22 at 9:35
|
show 2 more comments
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53427483%2fdetecting-clicks-on-qtreeview-icons%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
From what I understand you want to detect if you press an icon of some item in the QTreeView, let's say that this information is detected: what information do you want to obtain, do you want to obtain the QModelIndex or perform some action ?, on the other hand the second part of your question does not I extend it, could you explain me.
– eyllanesc
Nov 22 at 9:25
On the other hand, why the need to detect that click ?, the position of the icon depends on the QStyle that is very dependent on the OS so probably there is no answer, maybe you have an XY problem and then we can give you another alternative.
– eyllanesc
Nov 22 at 9:27
The problem is to detect the mouse click - in my case I will be performing an action depending on the data in the model, but that is irrelevant to the issue. The second part is related because the position of the icon within an item is controlled by its styling - but I see your point that it adds nothing to the question, so I will remove it. Thanks.
– mkam
Nov 22 at 9:30
As indicated, I think there is no solution since the position of the icon is very dependent on QStyle, for example if we check the paint method of the QStyledItemDelegate we see that the painted code.qt.io/cgit/qt/qtbase.git/tree/src/widgets/itemviews/… :
style->drawControl(QStyle::CE_ItemViewItem, &opt, painter, widget)
– eyllanesc
Nov 22 at 9:33
and many times the QStyle introduce numerical values to convenience that are not standard to give it a different style and that is easily if you execute your code in several OS, or use a different QStyle.
– eyllanesc
Nov 22 at 9:35