Details
-
Bug
-
Resolution: Out of scope
-
Not Evaluated
-
None
-
4.6.3
-
None
Description
In this example I added QgraphicsTextItem and QGraphicsRectItem in QGraphicsScene object.
In QGraphicsRectItem I disabled all transformations rect->setFlag(QGraphicsItem::ItemIgnoresTransformations); so the rect size is always the same after scaling but because of this enabled option the calculation of the new position after scaling is incorrect like you can see on the attached image.
If I disable rect->setFlag(QGraphicsItem::ItemIgnoresTransformations); everything works fine but after this the rect uses the scaling factor like QGraphicsTextItem.
Here I expected that the position is always at the right corner but it is not. Everytime the rect item has the same position.
mainwindow.h:
#include <QMainWindow> #include <QGraphicsScene> #include <QGraphicsTextItem> #include <QGraphicsRectItem> namespace Ui { class MainWindow; } class MainWindow : public QMainWindow { Q_OBJECT public: MainWindow(QWidget *parent = 0); ~MainWindow(); protected: void changeEvent(QEvent *e); QGraphicsScene *scene; QGraphicsTextItem *text; QGraphicsRectItem *rect; private: Ui::MainWindow *ui; private slots: void click123(); };
mainwindow.cpp:
#include "mainwindow.h" #include "ui_mainwindow.h" #include <QGraphicsSvgItem> #include <QGraphicsRectItem> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); scene = new QGraphicsScene(); ui->graphicsView->setScene(scene); connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(click123())); text = new QGraphicsTextItem(); text->setFlag(QGraphicsItem::ItemIsSelectable); text->setFlag(QGraphicsItem::ItemIsMovable); text->setPlainText("Then pour yourself a stiff Pimms, or squash if you're a nipper - we're drinks of course."); text->setTextWidth(80); text->setPos(50, 50); scene->addItem(text); rect = new QGraphicsRectItem(); rect->setFlag(QGraphicsItem::ItemIgnoresTransformations); rect->setRect(text->boundingRect().width(), text->boundingRect().height(), 6, 6); rect->setBrush(QBrush(QColor::fromRgb(0, 0, 255))); rect->setParentItem(text); } MainWindow::~MainWindow() { delete ui; } void MainWindow::changeEvent(QEvent *e) { QMainWindow::changeEvent(e); switch (e->type()) { case QEvent::LanguageChange: ui->retranslateUi(this); break; default: break; } } void MainWindow::click123() { ui->graphicsView->scale(4.0, 4.0); }