SFML community forums

Help => Window => Topic started by: Tenry on August 09, 2011, 08:21:25 pm

Title: GUI Integration (Qt): Why are graphics scaled on resize?
Post by: Tenry on August 09, 2011, 08:21:25 pm
Hi, I'm going to integrate SFML in Qt, I'm going to write a level editor.

I've followed SFML's tutorial about Qt and the drawing and everything works fine. But when I resize my window, I'd like my SFML widget to be resized, too.
It IS resized correctly, but everything I draw is scaled up. What is the problem?

I've tried something like this:
void QSFMLCanvas::resizeEvent(QResizeEvent *event)
{
  printf("New size: %dx%d\n", event->size().width(), event->size().height());
  SetSize(event->size().width(), event->size().height());
}
But that doesn't change anything.

Any ideas?
Title: GUI Integration (Qt): Why are graphics scaled on resize?
Post by: Laurent on August 09, 2011, 08:41:29 pm
It's not a problem, it's a feature ;)

The default view is not adjusted when the window is resized, so it always displays the exact same region of the 2D scene, stretched to the new size of the window. So you just have to resize the view if you want it to follow the new size.
Title: GUI Integration (Qt): Why are graphics scaled on resize?
Post by: Tenry on August 09, 2011, 08:52:37 pm
Quote from: Laurent
It's not a problem, it's a feature ;)

The default view is not adjusted when the window is resized, so it always displays the exact same region of the 2D scene, stretched to the new size of the window. So you just have to resize the view if you want it to follow the new size.
Hm...
sf::View View(sf::FloatRect(0, 0, event->size().width(), event->size().height()));
SetView(View);

I just have an empty screen :( I only see my blue background I draw, but not my 64x64 shape drawn about on the top left.
Title: GUI Integration (Qt): Why are graphics scaled on resize?
Post by: Laurent on August 09, 2011, 09:27:23 pm
If you use SFML 1.6, you must keep the view alive as long as it's used, you can't assign a temporary view. For convenience, you can directly modify the windows's default view (window.GetDefaultView()), so that you don't have to create a new one.
Title: GUI Integration (Qt): Why are graphics scaled on resize?
Post by: Tenry on August 09, 2011, 10:06:46 pm
Quote from: "Laurent"
If you use SFML 1.6, you must keep the view alive as long as it's used, you can't assign a temporary view. For convenience, you can directly modify the windows's default view (window.GetDefaultView()), so that you don't have to create a new one.


Okay. I wasn't sure whether I may change the default view.

Now it works very fine :)
Thanks!