Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: GUI Integration (Qt): Why are graphics scaled on resize?  (Read 3485 times)

0 Members and 1 Guest are viewing this topic.

Tenry

  • Full Member
  • ***
  • Posts: 120
  • Experienced Programmer
    • View Profile
    • Simon-Burchert.com
GUI Integration (Qt): Why are graphics scaled on resize?
« 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?
« Last Edit: March 26, 2012, 08:11:05 pm by Shy Guy »
Please note that my previous display name was "Shy Guy".

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
GUI Integration (Qt): Why are graphics scaled on resize?
« Reply #1 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.
Laurent Gomila - SFML developer

Tenry

  • Full Member
  • ***
  • Posts: 120
  • Experienced Programmer
    • View Profile
    • Simon-Burchert.com
GUI Integration (Qt): Why are graphics scaled on resize?
« Reply #2 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.
« Last Edit: March 26, 2012, 08:11:17 pm by Shy Guy »
Please note that my previous display name was "Shy Guy".

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
GUI Integration (Qt): Why are graphics scaled on resize?
« Reply #3 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.
Laurent Gomila - SFML developer

Tenry

  • Full Member
  • ***
  • Posts: 120
  • Experienced Programmer
    • View Profile
    • Simon-Burchert.com
GUI Integration (Qt): Why are graphics scaled on resize?
« Reply #4 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!
Please note that my previous display name was "Shy Guy".

 

anything