Issue
I'm trying to capture the screen area in the region of my pyqt4 app translucent, but i want exclude the widget "betwn = QPushButton('test')" in the capture, I'm trying to hide the widget using hide() like this: betwn.hide(), for be excluded before the capture, but not works, the "betwn" even hidden anyway is will captured.
Here my PyQt4 Code:
import sys
from PyQt4.QtGui import *
from PyQt4.QtCore import *
from datetime import datetime
app = QApplication(sys.argv)
widget = QWidget()
widget.setLayout(QVBoxLayout())
widget.setAttribute(Qt.WA_TranslucentBackground)
label = QLabel()
widget.layout().addWidget(label)
def capture():
p = QPixmap.grabWindow(QApplication.desktop().winId(),widget.geometry().x(),widget.geometry().y(),widget.geometry().width(),widget.geometry().height())
label.setPixmap(p)
def shoot():
betwn.hide()
capture()
betwn.show()
button = QPushButton('take screenshot', clicked=shoot)
betwn = QPushButton('test')
widget.layout().addWidget(button)
widget.layout().addWidget(betwn)
widget.show()
app.exec_()
Here my PySide Code:
import sys
from PySide.QtGui import *
from PySide.QtCore import *
from datetime import datetime
app = QApplication(sys.argv)
widget = QWidget()
widget.setLayout(QVBoxLayout())
widget.setAttribute(Qt.WA_TranslucentBackground)
label = QLabel()
widget.layout().addWidget(label)
def capture():
p = QPixmap.grabWindow(QApplication.desktop().winId(),widget.geometry().x(),widget.geometry().y(),widget.geometry().width(),widget.geometry().height())
label.setPixmap(p)
def shoot():
betwn.hide()
capture()
betwn.show()
button = QPushButton('take screenshot', clicked=shoot)
betwn = QPushButton('test')
widget.layout().addWidget(button)
widget.layout().addWidget(betwn)
widget.show()
app.exec_()
How i can do for exclude the widget "betwn = QPushButton('test')" in the capture? or If you know other way to capture the desktop area using the of the window without capture the window, using the coordinates of the window and the width and height?
Like this:
QPixmap.grabWindow(QApplication.desktop().winId(),widget.geometry().x(),widget.geometry().y(),widget.geometry().width(),widget.geometry().height());
Solution
When you call the hide method, it does not mean that the button will be closed at that moment, since it involves a repainting process that ends after the synchronous task ends, in these cases you must give adequate time for Qt to do that work and that can be done. make a QTimer::singleShot().
app = QApplication(sys.argv)
widget = QWidget()
widget.setLayout(QVBoxLayout())
widget.setAttribute(Qt.WA_TranslucentBackground)
label = QLabel()
widget.layout().addWidget(label)
def capture():
p = QPixmap.grabWindow(
QApplication.desktop().winId(),
*widget.geometry().getRect()
)
label.setPixmap(p)
betwn.show()
def shoot():
betwn.hide()
QTimer.singleShot(1, capture)
button = QPushButton("take screenshot", clicked=shoot)
betwn = QPushButton("test")
widget.layout().addWidget(button)
widget.layout().addWidget(betwn)
widget.show()
sys.exit(app.exec_())
Answered By - eyllanesc
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.