Qt-interest Archive, April 2007
How to do this in QT
Message 1 in thread
Hi,
I need to create a rectangle such that when the user clicks its first
point is selected and then as
the mouse is moved a tracker rectangle is shown with dotted lines with
the other end of the rectangle following the mouse,
and when the mouse is clicked again the actual retangle is created.
Something similar to PowerPoint.
Is there any predefined API to do this ? Beign new to QT, any hints to
approach this problem would be really helpful.
Thnx
Prateek
Message 2 in thread
Look at QRubberBand.
Keith
On 04-05-2007 12:25 AM, "Prateek Tiwari" wrote:
> Hi,
>
> I need to create a rectangle such that when the user clicks its first point is
> selected and then as
> the mouse is moved a tracker rectangle is shown with dotted lines with the
> other end of the rectangle following the mouse,
> and when the mouse is clicked again the actual retangle is created. Something
> similar to PowerPoint.
>
> Is there any predefined API to do this ? Beign new to QT, any hints to
> approach this problem would be really helpful.
>
> Thnx
> Prateek
Message 3 in thread
Thnx.
This is what I am trying.
I get the following error :
"An unhandled exception of type 'System.NullReferenceException' occurred
in Qt1.exe
Additional information: Object reference not set to an instance of an
object."
//Header File
#include <QMouseEvent>
#include <QRubberBand>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QWidget>
class MyView : public QGraphicsView
{
QRubberBand *rubberBand ;
QPoint origin ;
protected:
virtual void mousePressEvent(QMouseEvent *);
virtual void mouseMoveEvent(QMouseEvent *);
virtual void mouseReleaseEvent(QMouseEvent *);
public:
MyView(QGraphicsScene*);
};
//cpp file
#include <qapplication.h>
#include <qlabel.h>
#include <qrubberband.h>
#include "mywidget.h"
int WinMain(int argc, char** argv)
{
QApplication app(argc,argv);
QGraphicsScene *label = new QGraphicsScene();
label->setSceneRect(QRectF(0,0,100,100));
MyView view(label);
view.show();
return app.exec();
}
void MyView::mousePressEvent(QMouseEvent *event)
{
origin = event->pos();
if (!rubberBand)
rubberBand = new QRubberBand(QRubberBand::Rectangle, this);
rubberBand->setGeometry(QRect(origin, QSize()));
rubberBand->show();
}
void MyView::mouseMoveEvent(QMouseEvent *event)
{
rubberBand->setGeometry(QRect(origin, event->pos()).normalized());
}
void MyView::mouseReleaseEvent(QMouseEvent *event)
{
rubberBand->hide();
}
MyView::MyView(QGraphicsScene *scene) : QGraphicsView(scene)
{
this->rubberBand = NULL ;
}
Pl help me what is going wrong here. Maybe its a very stupid thing that
I am doing. :-(
Thnx
Prateek
________________________________
From: Keith Esau [mailto:keith.esau@xxxxxxx]
Sent: Thursday, April 05, 2007 11:32 AM
To: Qt Interest
Subject: Re: How to do this in QT
Look at QRubberBand.
Keith
On 04-05-2007 12:25 AM, "Prateek Tiwari" wrote:
Hi,
I need to create a rectangle such that when the user
clicks its first point is selected and then as
the mouse is moved a tracker rectangle is shown with
dotted lines with the other end of the rectangle following the mouse,
and when the mouse is clicked again the actual retangle
is created. Something similar to PowerPoint.
Is there any predefined API to do this ? Beign new to
QT, any hints to approach this problem would be really helpful.
Thnx
Prateek
Message 4 in thread
Well obviously you're getting the events out of order, try checking
if (rubberBand) before you use rubberBand->... or create the rubberBand
in the constructor.
Cheers,
Peter
> "An unhandled exception of type 'System.NullReferenceException'
occurred
> in Qt1.exe
>
> Additional information: Object reference not set to an instance of an
> object."
--
[ signature omitted ]
Message 5 in thread
Oops! Stupid me.
Thnx a lot.
Prateek
-----Original Message-----
From: Peter Prade [mailto:prade@xxxxxxxxxxx]
Sent: Thursday, April 05, 2007 3:47 PM
To: QtList
Subject: AW: How to do this in QT
Well obviously you're getting the events out of order, try checking if
(rubberBand) before you use rubberBand->... or create the rubberBand in
the constructor.
Cheers,
Peter
> "An unhandled exception of type 'System.NullReferenceException'
occurred
> in Qt1.exe
>
> Additional information: Object reference not set to an instance of an
> object."
--
[ signature omitted ]
Message 6 in thread
Than for your help. I have been able to draw the rubberband coorectly.
I am facing another problem.
The first time rectangle comes correct.
On subsequent mouse clicks, i Have lots of repaint issues.
Only bottom and right sides of the rectangle are shown
and the top and left edge is not displayed.
What could be the reason.
This is how I am handling the mouse events.
void MyView::mousePressEvent(QMouseEvent *event)
{
origin = event->pos();
if (!rubberBand)
rubberBand = new QRubberBand(QRubberBand::Rectangle, this);
rubberBand->setGeometry(QRect(origin, QSize()));
rubberBand->show();
}
void MyView::mouseMoveEvent(QMouseEvent *event)
{
if(rubberBand)
rubberBand->setGeometry(QRect(origin,
event->pos()).normalized());
}
void MyView::mouseReleaseEvent(QMouseEvent *event)
{
if(rubberBand){
rubberBand->hide();
QPoint startPoint = origin ;
QPoint endPoint = event->pos() ;
QRect rect(startPoint, endPoint);
rect.normalized();
QRectF floatRect(rect);
m_scene->addRect(floatRect);
}
}
Pl advise.
Many Thanx
Prateek
-----Original Message-----
From: Prateek Tiwari [mailto:ptiwari@xxxxxxxxxxx]
Sent: Thursday, April 05, 2007 5:34 PM
To: Peter Prade; QtList
Subject: RE: How to do this in QT
Oops! Stupid me.
Thnx a lot.
Prateek
-----Original Message-----
From: Peter Prade [mailto:prade@xxxxxxxxxxx]
Sent: Thursday, April 05, 2007 3:47 PM
To: QtList
Subject: AW: How to do this in QT
Well obviously you're getting the events out of order, try checking if
(rubberBand) before you use rubberBand->... or create the rubberBand in
the constructor.
Cheers,
Peter
> "An unhandled exception of type 'System.NullReferenceException'
occurred
> in Qt1.exe
>
> Additional information: Object reference not set to an instance of an
> object."
--
[ signature omitted ]
Message 7 in thread
> rubberBand->setGeometry(QRect(origin, QSize()));
Should be
rubberBand->setGeometry(QRect(origin, QSize(0,0)));
QSize() makes an 'invalid' size. You want a size that contains nothing.
I'm not sure if that will fix it though.
On 04-05-2007 7:58 AM, "Prateek Tiwari" wrote:
> Than for your help. I have been able to draw the rubberband coorectly.
> I am facing another problem.
>
> The first time rectangle comes correct.
> On subsequent mouse clicks, i Have lots of repaint issues.
> Only bottom and right sides of the rectangle are shown
> and the top and left edge is not displayed.
>
> What could be the reason.
> This is how I am handling the mouse events.
>
>
> void MyView::mousePressEvent(QMouseEvent *event)
> {
> origin = event->pos();
> if (!rubberBand)
> rubberBand = new QRubberBand(QRubberBand::Rectangle, this);
> rubberBand->setGeometry(QRect(origin, QSize()));
> rubberBand->show();
> }
>
> void MyView::mouseMoveEvent(QMouseEvent *event)
> {
> if(rubberBand)
> rubberBand->setGeometry(QRect(origin,
> event->pos()).normalized());
> }
>
> void MyView::mouseReleaseEvent(QMouseEvent *event)
> {
> if(rubberBand){
> rubberBand->hide();
> QPoint startPoint = origin ;
> QPoint endPoint = event->pos() ;
> QRect rect(startPoint, endPoint);
> rect.normalized();
> QRectF floatRect(rect);
> m_scene->addRect(floatRect);
> }
>
> }
>
> Pl advise.
>
> Many Thanx
> Prateek
>
> -----Original Message-----
> From: Prateek Tiwari [mailto:ptiwari@xxxxxxxxxxx]
> Sent: Thursday, April 05, 2007 5:34 PM
> To: Peter Prade; QtList
> Subject: RE: How to do this in QT
>
> Oops! Stupid me.
>
> Thnx a lot.
>
> Prateek
>
> -----Original Message-----
> From: Peter Prade [mailto:prade@xxxxxxxxxxx]
> Sent: Thursday, April 05, 2007 3:47 PM
> To: QtList
> Subject: AW: How to do this in QT
>
> Well obviously you're getting the events out of order, try checking if
> (rubberBand) before you use rubberBand->... or create the rubberBand in
> the constructor.
>
> Cheers,
> Peter
>
>> "An unhandled exception of type 'System.NullReferenceException'
> occurred
>> in Qt1.exe
>>
>> Additional information: Object reference not set to an instance of an
>> object."
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
Keith Esau
Senior Software Engineer (dpSHEET)
PDF Solutions, Inc.
keith.esau@xxxxxxx
913-599-6537 (work/home)
913-515-2135 (mobile)
kaesau@xxxxxxxxxxxxx (home/personal)
===========================================================================
CONFIDENTIALITY NOTICE: This email contains information that may be
confidential and privileged. Unless you are the intended recipient (or
authorized to receive for the intended recipient), you are prohibited from
reviewing, using, copying, forwarding, keeping, or disclosing to anyone
other than PDF Solutions, Inc. this email or any information in the email
(including any attachment). If you have received this email in error,
please send a reply email only to the sender <keith.esau@xxxxxxx> (delete
the original message body from the reply), and please delete this message
from your system. My apologies for the inconvenience, and thank you in
advance for your cooperation.
===========================================================================
--
[ signature omitted ]
Message 8 in thread
Have a look at QRubberBand:
http://doc.trolltech.com/4.2/qrubberband.html#details
there is even an example how to connect this with mouse events.
Cheers,
Peter
> Hi,
>
> I need to create a rectangle such that when the user clicks its first
> point is selected and then as
> the mouse is moved a tracker rectangle is shown with dotted lines with
the
> other end of the rectangle following the mouse,
> and when the mouse is clicked again the actual retangle is created.
> Something similar to PowerPoint.
>
> Is there any predefined API to do this ? Beign new to QT, any hints to
> approach this problem would be really helpful.
>
> Thnx
> Prateek
--
[ signature omitted ]