QGraphicsRectItem selected line
Hello,
It's my first post here, so sorry if I'm starting a thread which already has been answered. I googled for the answer, but found nothing useful...
Anyway - I'm working on a project with a QGraphicsView-Scene-RectItem class implementation. The main functions available to the user should be the dragging (already done), selecting (done in 50%), resizing (problem here) and deleting rectangles (QGraphicsRectItems).
The problem I have now is with the ItemIsSelectable flag. I set it in the constructor of MyRectangle class, which inherits from QGraphicsRectItem. This allows for selecting the item, but I would really need to change the line style when the item gets selected (now it's barely noticeable). How can this be achieved? Should I reimplement the mousePressEvent? If so - how to deselect all other items on the scene besides the one under the mouse...
I will really appreciate any help,
Sending regards,
Bill
Re: QGraphicsRectItem selected line
Quote:
Originally Posted by
Bill
Hello,
It's my first post here, so sorry if I'm starting a thread which already has been answered. I googled for the answer, but found nothing useful...
Next time also use the board search function;)
Two possibilities:
- Create your own QStyle
- reimp the paint function with
Code:
if (option
& QStyle::State_HasFocus) {
// draw a custom selection rect
}
// remove the selection flag and call the base implementation
o
->state
&= ~
QStyle::State_HasFocus;
Re: QGraphicsRectItem selected line
Hi,
Thank you for the rapid reply :-). The reimplementation of paint() works like a charm. I saw it in the Diagram application from "C++ GUI programming with Qt" (chapter 8), but didn't have a clue that I should use it. Thanks.
By the way - what would be your general suggestion to implementing resize handles on the rectangles (at least in one corner)? I found a couple of threads on Qt Centre concerning this topic...
Regards,
Bill