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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - toara

Pages: [1]
1
Graphics / Mouse position is misaligned
« on: October 30, 2022, 12:33:59 pm »
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!

Pages: [1]
anything