Was hoping someone had experience with the issue and knew what stupid mistake I was making.
Thank you for your prompt response, and also for making such a great 2D library. I've used it quite a bit over the years, and this is the first issue that's stumped me.
I'm running XFCE on CentOS 7 via Vagrant using Parallels. When I drag the DockWidget out of the MainWindow, it floats properly on its own, but when I re-dock it within the MainWindow, a visual artifact remains on the screen. Screenshot below. Also, posted below is complete and minimal code that should, hopefully, replicate the issue.
Thank you,
David
QSFMLCanvas.h#ifndef _QSFMLCANVAS_H_
#define _QSFMLCANVAS_H_
#include <SFML/Graphics.hpp>
#include <QWidget>
#include <QTimer>
class QSFMLCanvas : public QWidget, public sf::RenderWindow
{
public :
QSFMLCanvas(QWidget* Parent, const QPoint& Position, const QSize& Size, unsigned int FrameTime = 0);
virtual ~QSFMLCanvas();
private :
virtual void on_init();
virtual void on_update();
virtual QPaintEngine* paintEngine() const;
virtual void showEvent(QShowEvent*);
virtual void paintEvent(QPaintEvent*);
QTimer m_timer;
bool m_initialized;
};
#endif
QSFMLCanvas.cpp#include "QSFMLCanvas.h"
QSFMLCanvas::QSFMLCanvas(QWidget* Parent, const QPoint& Position, const QSize& Size, unsigned int FrameTime)
: QWidget(Parent), m_initialized(false)
{
// Setup some states to allow direct rendering into the widget
setAttribute(Qt::WA_PaintOnScreen);
setAttribute(Qt::WA_OpaquePaintEvent);
setAttribute(Qt::WA_NoSystemBackground);
// Set strong focus to enable keyboard events to be received
setFocusPolicy(Qt::StrongFocus);
// Setup the widget geometry
move(Position);
resize(Size);
// Setup the timer
m_timer.setInterval(FrameTime);
}
QSFMLCanvas::~QSFMLCanvas()
{
}
#ifdef Q_WS_X11
#include <Qt/qx11info_x11.h>
#include <X11/Xlib.h>
#endif
void QSFMLCanvas::showEvent(QShowEvent*)
{
if (!m_initialized)
{
#ifdef Q_WS_X11
XFlush(QX11Info::display());
#endif
// Create the SFML window with the widget handle
RenderWindow::create((sf::WindowHandle)(winId()));
// Let the derived class do its specific stuff
// NOTE: Inside on_init, the RenderWindow View should be assigned!
on_init();
// Setup the timer to trigger a refresh at specified framerate
connect(&m_timer, SIGNAL(timeout()), this, SLOT(repaint()));
m_timer.start();
m_initialized = true;
}
}
void QSFMLCanvas::paintEvent(QPaintEvent*)
{
RenderWindow::setActive(true);
// Let the derived class do its specific stuff
on_update();
// Display on screen
RenderWindow::display();
}
QPaintEngine* QSFMLCanvas::paintEngine() const
{
return 0;
}
void QSFMLCanvas::on_init() {}
void QSFMLCanvas::on_update() {}
MyWindow.h#ifndef _MYWINDOW_H_
#define _MYWINDOW_H_
#include "QSFMLCanvas.h"
#include <QMainWindow>
class MyWindow : public QMainWindow
{
Q_OBJECT
public:
MyWindow();
virtual ~MyWindow();
private:
QSFMLCanvas* canvas;
};
#endif // _MYWINDOW_H_
MyWindow.cpp#include "MyWindow.h"
#include <QtWidgets>
MyWindow::MyWindow()
{
QDockWidget *dock = new QDockWidget(tr("Scene"), this);
dock->setAllowedAreas(Qt::AllDockWidgetAreas);
canvas = new QSFMLCanvas(this, QPoint(0, 0), QSize(100, 100), 100/*10Hz*/);
canvas->show();
dock->setWidget(canvas);
addDockWidget(Qt::RightDockWidgetArea, dock);
}
MyWindow::~MyWindow()
{}
#include "MyWindow.moc"
main.cpp#include <QApplication>
#include "MyWindow.h"
int main(int argc, char** argv)
{
QApplication app(argc, argv);
MyWindow w;
w.setMinimumSize(800,600);
w.show();
return app.exec();
}