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

Author Topic: Integration with Qt Widgets  (Read 3381 times)

0 Members and 1 Guest are viewing this topic.

JayArby

  • Jr. Member
  • **
  • Posts: 68
    • View Profile
Integration with Qt Widgets
« on: March 21, 2013, 07:54:02 pm »
So I've been working on a project for a while now in which I am integrating SFML and Qt5. I'm just using SFML for drawing. But I have not found any really good way to manage it.

I have tried three different techniques so far:
1) create a sf::RenderWindow from my QWidget::winId() and set the QWidget attribute WS_PaintOnScreen
This works to a certain extent, but besides only working properly on Linux (which will be a problem) it causes other issues (I get lots of errors pertaining to QBackingStore::flush() and QWidget::paintEngine())

2) render into a sf::RenderTexture, then copy the texture to a sf::Image, load the data into a QImage and draw onto the QWidget with a QPainter.
This also worked to some extent, but besides the obvious performance hit that this method would cause, the pixel format used in sf::Image is not compatible with QImage, so some of the color channels get mixed up.

3) use a QGLWidget instead of a QWidget, create a sf::RenderWindow from my QGLWidget::winId(), and do painting inside of QGLWidget::paintGL().
I was kind of surprised that this worked at all, but I don't know the details of opengl or the way it is used in wither SFML or QGLWidget, so maybe someone can explain the behavior I observed. I understand that SFML's version of opengl may not be supported in Qt5, so that's probably part of the problem. But some things worked, such as drawing lines, shapes, etc. Loading textures did not work. I also got several opengl errors pertaining to invalid calls. What confused me about this was that I thought sf::RenderWindow QGLWidget would each create its own context, so I didn't really expect it to work at all. Then again, I don't know much about opengl.

Anyways, does anybody know a correct, cross-platform way to integrate sf::RenderTarget into Qt Widgets? The only material I've been able to find is outdated--it deals with Qt4 and SFML 1.6. Also, I guess I could roll back to Qt4 if absolutely necessary, but I'd really like not to.
« Last Edit: March 21, 2013, 07:56:27 pm by JayArby »

JayArby

  • Jr. Member
  • **
  • Posts: 68
    • View Profile
Re: Integration with Qt Widgets
« Reply #1 on: March 24, 2013, 01:19:49 pm »
Hmm...I guess no one has any ideas.

Anyway, at long last I found something that seems to work, although there is probably something technically wrong with it.  I'm using a QGLWidget and create a sf::RenderWindow from my QGLWidget::winId(), but I'm doing painting inside of QGLWidget::paintEvent() rather than paintGL(). I guess QGLWidget disable double buffering or something.

Anyway, if anyone has any insight into whether this is cross-platform or a good practice or whether it will cause any issues, please speak up!

Laurent, maybe the tutorial should be updated to use a QGLWidget?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Integration with Qt Widgets
« Reply #2 on: March 24, 2013, 02:54:20 pm »
There won't be tutorials anymore about integration with other toolkits.

And you're right, I have no idea since I haven't tested SFML with Qt 5 yet. I'm sorry :-\
Laurent Gomila - SFML developer

Jamin Grey

  • Newbie
  • *
  • Posts: 25
    • View Profile
    • Of Stranger Flames
Re: Integration with Qt Widgets
« Reply #3 on: September 04, 2013, 11:53:29 pm »
I'm using Qt5.1 with SFML 2 - I haven't had much problems modifying the original SFML 1.6 / Qt 4.6 tutorial.

A few minor modifications were needed, though I forget what exactly I changed.

Here's the code I've been using successfully for several good months.
Of Stranger Flames - My work-in-progress para-historical (and classically-inspired) 2D rpg.