yes,Originally Posted by zlatko
they are declared in the protected section...
yes,Originally Posted by zlatko
they are declared in the protected section...
So if i have undestand you we talk about ImageZoomer class?
Who is his parent?
a life without programming is like an empty bottle![]()
This class inherits the QMainWindow class and the header file for the class is :Originally Posted by zlatko
ImageZoomer.h
Qt Code:
{ Q_OBJECT public: ImageZoomer(Ui::MainWindow *_mw); ~ImageZoomer(); void scaleImage(double factor); protected: public slots: void open(); void zoomIn(); void zoomOut(); void zoomNormal(); void fitToWindow(); private: QFrame *frame; QScrollArea *sarea; Q3ScrollView *sview; double scalefactor; Ui_MainWindow *mwin; QPixmap fromImage; Q3Canvas *canvas; Q3CanvasView *canview; QMouseEvent *mEvent; Q3CanvasItem* moving; QPoint moving_start; QImage image; };To copy to clipboard, switch view to plain text mode
QMainWindow doesnt have slot void contentsMousePressEvent(QMouseEvent*);
a life without programming is like an empty bottle![]()
Hi,Originally Posted by zlatko
Okay.. This means that i will have to also inherit the class QCanvasView 'coz it contains the method contentsMousePressEvents(QMouseEvent *)...
Is it so?????
no, you just dont capture mouse events on a main window.
If you want to capture them in your canvas, make a class that extends QCanvas and override its mouse events.
Hi,Originally Posted by incubator
It means that i would make another class and its structure would look like this..
[HTML]
#include "imagezoomer.h"
class Sample : public QCanvas
{
public:
Sample();
protected:
void contentsMousePressEvent(QMouseEvent *);
private:
ImageZoomer *zoom;
};
Sample::Sample()
{
ImageZoomer zoom = new ImageZoomer;
}
void Sample::contentsMousePressEvent(QMouseEvent *event)
{
code
}
[/HTML]
Is it so??????????????
sort of, but your ImageZoomer extends a main window, so that class should have a private member MyCanvas that extends a QCanvas (if you use Qt4 its Q3Canvas I think)
and in that MyCanvas class you override your mouse events.
Hi...
The new class which i have created is CanvasMouse..
Now in my ImageZoomer i have created a CanvasMouse *canmouse variable which would call the CanvasMouse which inherits the Q3CanvasView....
In imageZoomer i have created a Q3CanvasView and have passed in the constructor of the CanvasMouse which reads this
CanvasMouse(Q3CanvasView *canview): canvasview(canview)
Now class CanvasMouse contains all the canvas related functionalities...
is this approach correct ?????
You sholdn't give Q3CanvasView parametr. You need give only pointer on parent class.Originally Posted by Kapil
Qt Code:
CanvasMouse *canmous = new CanvasMouse(this); ***** CanvasMouse(ImageZoomer*p): canvasview(p) { }To copy to clipboard, switch view to plain text mode
p.s. also you could give any parametres (if you dont need it in future )
a life without programming is like an empty bottle![]()
Hi..Originally Posted by zlatko
won't this result in a circular dependency... i have included the header file "canmouse.h" in my ImageZoomer class and created an object of it.. Now when i pass the ImageZoomer object to CanMouse class, it would i suppose result into a circular dependency...
Isn't it so?????
yes, there is no need to pass the imagezoomer to your canvas, no need at all...
just have the canvas as member of imagezoomer and add this to one of your layouts
Bookmarks