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.










share|improve this question
























  • 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















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.










share|improve this question
























  • 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













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.










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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


















  • 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

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















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






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Contact image not getting when fetch all contact list from iPhone by CNContact

count number of partitions of a set with n elements into k subsets

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks