How to create screenshot of QWidget?

前端 未结 2 1423
感情败类
感情败类 2021-02-08 01:10

I work at my homework in Qt Creator, where I paint to QWidget and I need to save some part of this QWdiget.

I tried to solve this problem:

 QPixmap pixma         


        
相关标签:
2条回答
  • 2021-02-08 01:30

    You can use QWidget::render for this. Assuming rectangle is a QRect:

    QPixmap pixmap(rectangle->size()); 
    widget->render(&pixmap, QPoint(), QRegion(rectangle));
    
    0 讨论(0)
  • 2021-02-08 01:38

    From QWidget::Grab:

    QPixmap QWidget::grab(const QRect &rectangle = QRect(QPoint(0, 0), QSize(-1, -1)))
    
    0 讨论(0)
提交回复
热议问题