Hi,
I know that I found a similar topic somewhere this for ex. but it does not help me.
Anyway, I really can't figure out why the graphicsview always returns QSize(98,28) as it's size, geometry and viewport size upon construction.
It's a problem because I intend to draw something on the scene based on the actual viewport coordinates.
This of course is not possible since I get the wrong viewport size results.
Here is a small snippet of what I did and would like to do:
//inside a QMainWindow constuctor:
Mainwindow
::Mainwindow(QWidget *parent
)
{
...
view->setScene(scene);
view->show();
drawSomething();
qDebug() << view->viewport()->size();
qDebug() << view->geometry();
...
}
...
void Mainwindow::drawSomething()
{
//draw 5 lines equally spaced aroud the width of the viewport
//does not work because I get the 98 pixels as the width of the viewport width
qreal intervall = view->viewport()->width() / 5;
for(int i = 0; i < 5; ++i)
{
scene->addLine(intervall*i, 0, intervall*i, 1);
}
}
// returns
//inside a QMainWindow constuctor:
Mainwindow::Mainwindow(QWidget *parent)
: QMainWindow(parent)
{
...
QGraphicsScene *scene = new QGraphicsScene(this);
QGraphicsView *view = new QGraphicsView(this);
view->setScene(scene);
view->show();
drawSomething();
qDebug() << view->viewport()->size();
qDebug() << view->geometry();
...
}
...
void Mainwindow::drawSomething()
{
//draw 5 lines equally spaced aroud the width of the viewport
//does not work because I get the 98 pixels as the width of the viewport width
qreal intervall = view->viewport()->width() / 5;
for(int i = 0; i < 5; ++i)
{
scene->addLine(intervall*i, 0, intervall*i, 1);
}
}
// returns
QSize(98, 28)
QRect(0,0 100x30)
To copy to clipboard, switch view to plain text mode
These values are not the actual values of the Graphicsview of course. Now the problem is that I need to draw lines for ex.
based on the actual viewport size.
Many thanks.
Bookmarks