Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved]about the coordinates of my screen. Qt

[Solved]about the coordinates of my screen. Qt

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Project try
    wrote on last edited by
    #1

    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:
    @
    this->setWindowFlags(Qt::FramelessWindowHint|Qt::WindowStaysOnTopHint);
    this->setWindowState(Qt::WindowFullScreen);
    Image=new QPixmap;
    screen=QGuiApplication::primaryScreen();
    *Image=screen->grabWindow(0);
    pal.setBrush(this->backgroundRole(),QBrush(*Image));
    this->setPalette(pal);
    @
    second the mouse events:
    @
    void FramelessWindow::mousePressEvent(QMouseEvent *event){
    if(event->button()==Qt::LeftButton){
    origin= event->pos();
    rubberBand->setGeometry(QRect(origin,QSize()));
    rubberBand->show();

        }
    }
    
    void FramelessWindow::mouseMoveEvent(QMouseEvent *event){
        rubberBand->setGeometry(QRect(origin,event->pos()).normalized());
    
       /*
        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){

        rubberBand->hide();
        QRect Rectangle(origin,event->pos());
        QPixmap image=QPixmap::grabWidget(this,Rectangle);
        image.save("TEST.png","png");
    close();
    
    
    }
    

    @

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

    1 Reply Last reply
    0
    • P Offline
      P Offline
      Project try
      wrote on last edited by
      #2

      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());

      image.save("TEST.png","png");
      

      @

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andreyc
        wrote on last edited by
        #3

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

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

        1 Reply Last reply
        0
        • P Offline
          P Offline
          Project try
          wrote on last edited by
          #4

          ^

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

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved