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());
}
}
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, Ui::MainWindow()
{
setupUi(this);
QGraphicsScene * scene = new QGraphicsScene(this);
graphicsView->setScene(scene);
QPoint point1(0, 0);
QPoint point2(1000, 0);
addBanner(scene, point1, point2, "POLICE - STOP");
}
void MainWindow::addBanner(QGraphicsScene * scene
, const QPoint & start
, const QPoint & end
, const QString & text) const
{
const int height = 25;
const int spaceing = 40;
QPen pen(Qt::black, 2, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
QBrush brush(Qt::yellow);
QFont font("Arial", 12);
QPoint pos(start);
QRect rect = QRect(start, QPoint(end.x(), end.y() + height));
QGraphicsRectItem * rect_item = scene->addRect(rect ,pen, brush);
rect_item->setFlag(QGraphicsItem::ItemClipsChildrenToShape);
while(pos.x() < end.x())
{
QGraphicsTextItem * item = new QGraphicsTextItem(text, rect_item, scene);
item->setFont(font);
item->setPos(pos);
item->clipPath();
pos.setX(pos.x() + spaceing + item->boundingRect().right());
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks