Hi there,
I am new to QT Programming so I realize this problem seem rather stupid. I apologize in advance.
So basically I am trying to draw on an image using QPainter.
I have a QLabel on a QScrollArea:
scrollArea->setWidget(imageLabel);
imageLabel = new QLabel;
scrollArea = new QScrollArea;
scrollArea->setWidget(imageLabel);
To copy to clipboard, switch view to plain text mode
after which I go ahead and load an image as a pixmap:
imageLabel
->setPixmap
(QPixmap::fromImage(image
));
imageLabel->setPixmap(QPixmap::fromImage(image));
To copy to clipboard, switch view to plain text mode
Now I have tried creating a function:
paintme.
drawLine(QLineF(10.0,
80.0,
90.0,
20.0));
}
void Planning::paintNodes(QPaintEvent *){QPainter paintme(this);
paintme.drawLine(QLineF(10.0, 80.0, 90.0, 20.0));
}
To copy to clipboard, switch view to plain text mode
In addition, i tried creating an action like so:
drawNodesAct
= new QAction(tr
("Draw &Nodes"),
this);drawNodesAct
->setShortcut
(tr
("Ctrl+N"));drawNodesAct
->setEnabled
(false);connect
(drawNodesAct,
SIGNAL(triggered
()),
this,
SLOT(paintNodes
(image.
rect())));
drawNodesAct = new QAction(tr("Draw &Nodes"),this);drawNodesAct->setShortcut(tr("Ctrl+N"));drawNodesAct->setEnabled(false);connect(drawNodesAct, SIGNAL(triggered()), this, SLOT(paintNodes(image.rect())));
To copy to clipboard, switch view to plain text mode
and I try to call paintNodes from another function.
I am a little confused as to what I should define the parameter 'QPaintEvent *' to pass in as?
I read up a little and it said I should pass a QRect. How would I be able to get this code to work to merely draw a line on the loaded image?
I'm working on my senior design for electrical engineering and trying to create a GUI for our A* Planning algorithm.
Any help will be appreciated!
Bookmarks