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

Author Topic: [Solved] [Qt5+SFML2.1] Resizing a SFML canvas in a QLayout  (Read 2421 times)

0 Members and 1 Guest are viewing this topic.

daijin12

  • Newbie
  • *
  • Posts: 16
    • View Profile
[Solved] [Qt5+SFML2.1] Resizing a SFML canvas in a QLayout
« on: November 28, 2013, 02:42:38 am »
Hello everyone,

I have a problem in a program using SFML 2.1 integrated in a Qt5 interface.
I placed the QSFMLCanvas in the layout of a QStackedWidget itself inserted into the centralwidget of a QMainWindow:
 
Sfml = new QSFMLCanvas(this);
   
widget_container = new QStackedWidget(this);
widget_container->addWidget(Sfml);
widget_container->setCurrentWidget(Sfml);
widget_container->layout()->setAlignment(widget_container,Qt::AlignCenter);
setCentralWidget(widget_container);
 

It works fine under Linux (Fedora 18), the canvas is well resized with the QMainWindow.

By cons, under Windows 7, the canvas keeps it original size and is positioned at the bottom left when you resize the QMainWindow.

I tried to see what was happening by printing the size of the QWidget and of the RenderWindow which are the parent classes of QSFMLCanvas in the resizeEvent() function:
void QSFMLCanvas::resizeEvent(QResizeEvent *event)
{
    std::cout << size().width() <<" " << size().height()
              <<  " " << getSize().x << " " << getSize().y <<  std::endl;
}
 

and here is an example of the output:
815 639 700 579
815 639 700 579
825 641 700 579
825 641 700 579
835 644 700 579
835 644 700 579
842 646 700 579

RenderWindow size does not vary while the QWidget is well resized.

I tried to add a setSize() in the resizeEvent() function but it does not change anything:
void QSFMLCanvas::resizeEvent(QResizeEvent *event)
{
    setSize(sf::Vector2u(event->size().width(),event->size().height()));
   
        std::cout << size().width() <<" " << size().height()
              <<  " " << getSize().x << " " << getSize().y <<  std::endl;
}
 

If someone has an idea to fix that, it would help me a lot.

Thank you in advance and sorry if my english is bad,

daijin12
« Last Edit: May 27, 2014, 05:24:18 pm by daijin12 »

daijin12

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: [Solved] [Qt5+SFML2.1] Resizing a SFML canvas in a QLayout
« Reply #1 on: May 27, 2014, 05:26:59 pm »
Hi,

I finally solved this, by updating SFML from the git repository.

I now works quite well but still need to reimplement resizeEvent function
void QSFMLCanvas::resizeEvent(QResizeEvent *event)
{
    setSize(sf::Vector2u(event->size().width(),event->size().height()));
}

It works well for both Fedora and Windows.

 

anything