Hi Amleto, you've made my week. Thinking about it, it's just logical. I had thought, "this->showMaximized();" would have put me onto the sunny side of a maximized window already - but, of course, the "mainWin.show();" is yet to come after all the stuff I did in the constructor. Actually I took a different approach in the details, but you are right, the real problem is: i have to wait for the resize. I've tried it out quickly with a single shot timer - BINGO.
QPointF tl
(view
->horizontalScrollBar
()->value
(), view
->verticalScrollBar
()->value
());
QPointF br
= tl
+ view
->viewport
()->rect
().
bottomRight();
QMatrix mat
= view
->matrix
().
inverted();
rectItem->setPos(view->mapToScene(view->viewport()->pos()));
visibleRect.setRect(visibleRect.x(),visibleRect.y(),visibleRect.width()-1,visibleRect.height()-1); //the "-1" is just for being able to see the red pen
rectItem
->setPen
(QPen(Qt
::red));
rectItem->setRect(visibleRect);
QPointF tl(view->horizontalScrollBar()->value(), view->verticalScrollBar()->value());
QPointF br = tl + view->viewport()->rect().bottomRight();
QMatrix mat = view->matrix().inverted();
QRectF visibleRect=mat.mapRect(QRectF(tl,br));
rectItem->setPos(view->mapToScene(view->viewport()->pos()));
visibleRect.setRect(visibleRect.x(),visibleRect.y(),visibleRect.width()-1,visibleRect.height()-1); //the "-1" is just for being able to see the red pen
rectItem->setPen(QPen(Qt::red));
rectItem->setRect(visibleRect);
To copy to clipboard, switch view to plain text mode
Edit:
To make it work in the initialisation of my real program it was not enough to hook into the resizeEvent, I also had to call the calculation from QEvent::show, as done here:
{
emit this->centralWidgetWasResized();
}
bool CentralWidget
::event(QEvent * event
) {
if (event
->type
()==QEvent::Show) emit this
->centralWidgetWasResized
();
event->ignore();
return true;
}
void CentralWidget::resizeEvent(QResizeEvent *)
{
emit this->centralWidgetWasResized();
}
bool CentralWidget::event(QEvent * event)
{
if (event->type()==QEvent::Show) emit this->centralWidgetWasResized();
event->ignore();
QWidget::event(event);
return true;
}
To copy to clipboard, switch view to plain text mode
Still, though, I'll have to keep in mind that the correct size is provided only after nearly all my constructors' work has been done.
Thank you very much for all the effort you've put into this!
Bookmarks