Hello,
My problem is this:
I'm trying to make a cross-plot (reference) and I've come to the point where I want to draw my QList<Node> listOfNodes.
My node class is (something) like this
#ifndef CROSSPLOTNODE_H
#define CROSSPLOTNODE_H
#include <QtGui>
#include <QtGui/QColor>
#include <QtGui/QGraphicsItem>
#include "Labwell.h"
#include "AbstractNode.h"
{
public:
~CrossPlotNode();
void setStyle(Qt::PenStyle style);
void setPenWidth(qreal width);
private:
LabWell *_well;
QList<AbstractNode> nodeList;
};
#endif
#ifndef CROSSPLOTNODE_H
#define CROSSPLOTNODE_H
#include <QtGui>
#include <QtGui/QColor>
#include <QtGui/QGraphicsItem>
#include "Labwell.h"
#include "AbstractNode.h"
class CrossPlotNode : public QGraphicsItem
{
public:
CrossPlotNode(LabWell *well, QString Cx, QString Cy, QGraphicsScene *parent);
~CrossPlotNode();
void paint(QPainter *painter, const QStyleOptionGraphicsItem *item, QWidget *widget);
void setPen(const QPen);
void setColor(const QColor);
void setStyle(Qt::PenStyle style);
void setPenWidth(qreal width);
private:
LabWell *_well;
QString _Cx;
QString _Cy;
QList<AbstractNode> nodeList;
QPen m_pen;
};
#endif
To copy to clipboard, switch view to plain text mode
and, just in case, abstractNode is something like this:
#ifndef ABSTRACTNODE_H
#define ABSTRACTNODE_H
#include <QtGui>
{
public:
protected:
private:
qreal depth;
};
#endif
#ifndef ABSTRACTNODE_H
#define ABSTRACTNODE_H
#include <QtGui>
class AbstractNode : public QGraphicsItem
{
public:
void setValues(QPointF points);
QPointF getValues();
QRectF boundingRect() const;
protected:
void mousePressEvent(QGraphicsSceneMouseEvent *event);
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
private:
qreal depth;
QPointF values;
};
#endif
To copy to clipboard, switch view to plain text mode
As you can see, they are data storage and handling classes. Now I want to draw CrossPlotNode from a CrossPlotView class (because, I believe, that's how I should do it. QGraphicsItems are graphic objects containers and something like a view, maybe? -I normally call it canvas, "A place where stuff can be drawn", not really sure how it's called in Qt...- I think it's a QGraphicsView which is a graphics display?).
That's pretty much how my classes, but I just don't understand how to draw something.
As a simple reference, I'd like to grab a node's boundingRect and use it to draw a rectangle in my View with those very same values (posX, posY, h, w).
If I'm not clear, please do let me know. I'm very new at QT (never really worked on GUI's) and it wouldn't surprise me if I wasn't clear enough.
Thanks in advance,
Alitoh
EDIT
I am aware that AbstractNode does NOT have a constructor. It's just that I haven't made up my mind about how it will work, to a certain degree because of this particular inquiry. Just wanted to clarify that.
EDIT2
I just read this and, albeit EXTREMELY helful (and might shed some light into future possible questions) does not answer my question. I'll add that I DO read the documentation but, sometimes, it's rather hard to follow and some things are not always quite clear.
Bookmarks