Hello everyone
So, I followed this nice guide on how to get SFML and Qt to works together (https://github.com/SFML/SFML/wiki/Tutorial%3A-Integrating-SFML-into-Qt). Reason being: I want the menu bar but unfortunately SFML does not offer that :(. QFrame wasn't gonna cut it, so I used QMainWindow instead:
int main(int argc, char* argv[]) {
QApplication application(argc, argv);
QMainWindow window;
// our sfml view widget
QSfml qsfml;
// throwing our sfml view widget into the window so it renders stuff
window.setCentralWidget(&(qsfml));
// the menu bars
QMenu* gameOptions = window.menuBar()->addMenu("Options");
gameOptions->addAction(qsfml.newGameAct);
gameOptions->addAction(qsfml.exitGameAct);
gameOptions->addSeparator();
gameOptions->addAction(qsfml.closeWindowAct);
window.resize(QSize(768, 570));
qsfml.setSize(sf::Vector2u(768, 570));
window.show();
return application.exec();
}
And as I usually do, I used sf::Mouse::getPosition to grab the cursor position relative to the window, then I set the rectangle position to be the cursor's position, unfortunately it doesn't seem to like Qt very much and the rectangle gets misaligned by quite a bit
From my experience this usually happen when the window is squished or resized or something similar, but I have made sure that they are of the same size by calling resize and setSize on window and the SFML widget respectively
Also, one weird thing is that using 640x480 resolution for the SFML widget works absolutely fine, but I need a bigger window :\
I'm on linux with KDE Plasma X11, if that helps
Thanks a lot in advanced!
Sorry for the complete lack of information and a slow response from my end, I didn't expect how busy I was gonna get :P
Anyway I have this bit of code responsible for getting the mouse position:
void QSfml::UpdateMousePosition() {
this->mousePos = sf::Mouse::getPosition(*this);
}
And this bit responsible for drawing the rectangle:
void QSfml::Render() {
this->tile.setPosition(this->mousePos.x, this->mousePos.y);
this->draw(this->tile);
}
The result was as you can see from the line above
The provided code only shows the basic Qt setup, so kind of hard to see what's actually going on.
Since the code is rather similar to the official guide, I didn't think it was worth including, but just in case, I have uploaded the code to Github:
https://github.com/toaranotdev/llk
Is the SFML "window" rendered at 0,0 inside the Qt window?
Yes
What you just use getPosition() without passing the window and get the Qt window position yourself and do the relative calculation in your own code?
I'm too big of a noob to do that obviously XD