[Qt-interest] Signals emitted by QSceneView
Brian McKinnon
bpmckinnon.qt at gmail.com
Mon Nov 29 18:48:15 CET 2010
I think I have found a solution.
class DragableRectangleItem : public QGraphicsRectItem
{
public:
DragableRectangleItem( QGraphicsItem * parent = 0 );
DragableRectangleItem( const QRectF & rect, QGraphicsItem * parent = 0
);
DragableRectangleItem( qreal x, qreal y, qreal width, qreal height,
QGraphicsItem * parent = 0 );
protected:
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent * event);
};
void DragableRectangleItem::mouseMoveEvent(QGraphicsSceneMouseEvent * event)
{
if(!scene()->sceneRect().contains(event->scenePos()))
{
QDrag * drag = new QDrag(event->widget());
QMimeData * mimeData = new QMimeData;
mimeData->setText("Hello World");
drag->setMimeData(mimeData);
scene()->removeItem(this);
delete this;
Qt::DropAction dropAction = drag->exec();
}
else
QGraphicsRectItem::mouseMoveEvent(event);
}
In addition I am using:
void ShapeGraphicsView::resizeEvent(QResizeEvent * event)
{
QGraphicsView::resizeEvent(event);
scene()->setSceneRect(rect());
}
To make the scene the same size as the view (poorly I'm sure).
Does this seem reasonable?
Does anyone have an opinion about calling "delete this;"? I have seen it
used before... but I feel unease about using it.
On Mon, Nov 29, 2010 at 11:32 AM, Christian Gagneraud <
cgagneraud at techworks.ie> wrote:
> On 11/29/2010 03:16 PM, Brian McKinnon wrote:
> > I set the sceneRect and now the scroll bars don't come up, but I'm still
>
> Perhaps the size of your view is bigger than the scene's size
> multiplied by the zoom factor. Hence no need for scrollbar.
> Anyway you can force scrollbars to be always displayed:
> http://doc.qt.nokia.com/4.7/qt.html#ScrollBarPolicy-enum
> As QGraphicsView is derived from QAbstractScrollArea.
>
> My 2 cents,
> Chris
>
>
> > not getting any leave event. It looks like I may just need to initiate
> > a drag event when I click on an item. If that is the case I can
> > probably still move the object around the scene using the drag event
> > slots to move the item... but this seems sort of hacky. Does anyone
> > know if any signal is sent when a selected object is moved out of the
> > scene or view?
> >
> > On Fri, Nov 26, 2010 at 12:57 PM, Sean Harmer
> > <sean.harmer at maps-technology.com
> > <mailto:sean.harmer at maps-technology.com>> wrote:
> >
> > Hi,
> >
> > On Friday 26 November 2010 16:49:14 Oliver.Knoll at comit.ch
> > <mailto:Oliver.Knoll at comit.ch> wrote:
> > > On 2010-11-26 Brian Brian McKinnon wrote:
> > > > ... I've been trying to overload the leaveEvent,
> > > > mouseLeaveEvent, ... well pretty much any leave event in either
> the
> > > > view, scene, or item that I can find with no luck. Is there a
> > > > notification that gets set out when a mouse leaves a view while
> > dragging
> > > > an item in the scene?
> > >
> > > I am just doing my first steps with QGraphicsScene/View, hence I
> > do not
> > > have much experience with that.
> > >
> > > In my case I observed that the QGraphicsScene "bounding box"
> > seems to be
> > > enlarged once I move an item out "into the invisible". I notice
> this
> > > because scrollbars appear and the scrollable area becomes bigger.
> > >
> > > I don't think QGraphicsView/Scene would emit a "mouse leave"
> > event while
> > > dragging, because enlarging the area seems to be the intended
> action.
> >
> > Not sure if it helps here, but you can prevent that behaviour by
> > explicitly
> > setting a sceneRect on your scene.
> >
> > Sean
> > _______________________________________________
> > Qt-interest mailing list
> > Qt-interest at trolltech.com <mailto:Qt-interest at trolltech.com>
> > http://lists.trolltech.com/mailman/listinfo/qt-interest
> >
> >
> >
> >
> > _______________________________________________
> > Qt-interest mailing list
> > Qt-interest at trolltech.com
> > http://lists.trolltech.com/mailman/listinfo/qt-interest
>
>
> --
> Christian Gagneraud,
> Electronics and software engineer
>
> TechWorks Marine Ltd
> 4a, Park Lane
> Dun Laoghaire, Co Dublin
> Ireland
>
> Tel: + 353 1 2365990
> Fax: + 353 1 2365992
> Web: www.techworks.ie
>
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20101129/8f83d4b9/attachment.html
More information about the Qt-interest-old
mailing list