How to draw a line with tiled images with QPainter?
Greetings,
I would like to know if it is possible to draw a line with tiled images as a background on it. I have tried to use QPen (width=20) with QBrush and Qt:TexturePattern, but this did not work correctly. Is there another way?
Thank you,
MadBear
Re: How to draw a line with tiled images with QPainter?
try using QPen width 0 and QBrush::TexturePattern
Quote:
Originally Posted by MadBear
...but this did not work correctly. Is there another way?
What you mean by this, show the sample output, so that someone can point out the problem.
Re: How to draw a line with tiled images with QPainter?
Greetings,
Thank you for your reply. Ok I will try to explain what I am trying to do. I must create QGraphicsItem that is like police tape (you see it in crime scenes) that prevents civilians to cross (it is a tape that says "POLICE - STOP" in constant intervals). My idea is that user clicks control points and then I create QPainterPath with lines through those control points. Control points can also be moved around QGraphicsScene. The problem is that line betwen control points. How can I create line that looks like that police tape. I have tried with texture for QBrush, but that created something like:
PO
LI
CE
-
ST
OP
Is there perhaps a different way how I can create this?
Thank you,
MadBear
1 Attachment(s)
Re: How to draw a line with tiled images with QPainter?
Will this work
Code:
MainWindow
::MainWindow(QWidget *parent
) , Ui::MainWindow()
{
setupUi(this);
graphicsView->setScene(scene);
addBanner(scene, point1, point2, "POLICE - STOP");
}
{
const int height = 25;
const int spaceing = 40;
QPen pen
(Qt
::black,
2, Qt
::SolidLine, Qt
::FlatCap, Qt
::MiterJoin);
while(pos.x() < end.x())
{
item->setFont(font);
item->setPos(pos);
item->clipPath();
pos.setX(pos.x() + spaceing + item->boundingRect().right());
}
}
Re: How to draw a line with tiled images with QPainter?
Greetings,
Thank you for your reply. But it does not work quite the way I wanted it. I did not notice, that this forum erased all my spaces in my example. So that was supposed to be a diagonal line (not vertical). And when I changed point2 to (1000, 30) the program didn't work anymore.
Thank you again.
Regards,
MadBear
Re: How to draw a line with tiled images with QPainter?
The example I post will work only for horizontal banners, you need to modify it for drawing to diagonal, using QPainterPath (you cannot use QGraphicsRectItem and QGraphicsTextItem)
I was only trying to give an example :)