[Solved]about the coordinates of my screen. Qt

  • I've posted about a problem yesterday of letting the widget completely transparent , but still haven't solved it... any ways there was another solution which it taking a picture of my primary screen and set it as the background of my widget and the user can select what he wants which is a nice idea and it's working.

    Except at the last thing I should do , which is saving the picture just to check if it's working and I got a weird problem ,

    when I drag the mouse from the top left it works fine..

    but when I drag from anywhere like top right it gives me a wrong picture " wrong place or coordinates "

    first the code that sets the background of my dialog:
    Image=new QPixmap;
    second the mouse events:
    void FramelessWindow::mousePressEvent(QMouseEvent *event){
    origin= event->pos();

    void FramelessWindow::mouseMoveEvent(QMouseEvent *event){
        QRect Rectangle(origin,event->pos());
        QPixmap image=QPixmap::grabWidget(this,Rectangle);
        image.save("TEST.png","png"); // same problem here and in mousereleaseevent

    the release event:
    void FramelessWindow::mouseReleaseEvent(QMouseEvent *event){

        QRect Rectangle(origin,event->pos());
        QPixmap image=QPixmap::grabWidget(this,Rectangle);


    Only when I drag from top left to down right it works.

  • Finally figured out why it causes this :D

    I've just read about the function normalized and it solved it:
    QPoint a= mapToGlobal(origin);
    QPoint b=event->globalPos();
    QRect Rectangle(a,b);
    //QPixmap image=QPixmap::grabWidget(this,Rectangle);
    QPixmap image=QWidget::grab(Rectangle.normalized());



  • You need to "normalize":http://qt-project.org/doc/qt-5/qrect.html#normalized the rectangle.

    [EDIT] I see you have found it already :-)

  • ^

    Thank you for all your help , I wouldn't have solved the problem in my last post without your help :D

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.