How to create a line between 2 points with QLabel?
-
@frnklu20
Well the image has to be as big as the points
like 0,0 and 100,100 , the pixmap must be 100x100
But if you want to click on it, an image is not so good as it
has no idea where line is. so it needs the point anyway.Even with a custom widget, it must still be as big as the span between the points.
So what should happen when you click the line at any part of it ?
-
@frnklu20
well you need to store the 2 points for each line and
then use math to find out if the user hits a line on mousePressed.
How is the lines stored now ? ( the points you use to draw it )This explains it well
http://www.jeffreythompson.org/collision-detection/line-point.php -
Hi,
Since you seem to want to interact and have things working dynamically, did you consider the Graphics View Framework ?
-
Did you check the Qt documentation and related examples ?
-
Yes!
But i'm having a problem.I saw in a video a guy using the the graphic view framework in a QDialog
That's the code:
dialog.h
class Dialog : public QDialog { Q_OBJECT public: explicit Dialog(QWidget *parent = nullptr); ~Dialog(); private: Ui::Dialog *ui; QGraphicsScene *scene; QGraphicsEllipseItem *ellipse; QGraphicsRectItem *rectangle; };
dialog.cpp
QDialog(parent), ui(new Ui::Dialog) { ui->setupUi(this); scene= new QGraphicsScene(this); ui->graphicsView->setScene(scene);////the problem is here! QBrush redBrush(Qt::red); QPen blackpen(Qt::black); ellipse=scene->addEllipse(10,10,100,100,blackpen,redBrush); }
It says that no member named 'graphicView' in Ui::Dialog, so how can i fix it?
i want to use the application in qwidget or qdialog class -
Did you add a QGraphicsView widget name
graphicsView
through designer to your dialog ?