本文整理汇总了C++中QDesktopWidget::winId方法的典型用法代码示例。如果您正苦于以下问题:C++ QDesktopWidget::winId方法的具体用法?C++ QDesktopWidget::winId怎么用?C++ QDesktopWidget::winId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QDesktopWidget
的用法示例。
在下文中一共展示了QDesktopWidget::winId方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: grabColor
void ScreenSelector::grabColor()
{
m_selectionRect = m_selectionRect.normalized();
QDesktopWidget* desktop = QApplication::desktop();
int screenNum = desktop->screenNumber(m_selectionRect.topLeft());
QScreen* screen = QGuiApplication::screens()[screenNum];
QPixmap screenGrab = screen->grabWindow(desktop->winId(),
m_selectionRect.x(), m_selectionRect.y(), m_selectionRect.width(), m_selectionRect.height());
QImage image = screenGrab.toImage();
int numPixel = image.width() * image.height();
int sumR = 0;
int sumG = 0;
int sumB = 0;
for (int x = 0; x < image.width(); ++x) {
for (int y = 0; y < image.height(); ++y) {
QColor color = image.pixel(x, y);
sumR += color.red();
sumG += color.green();
sumB += color.blue();
}
}
QColor avgColor(sumR / numPixel, sumG / numPixel, sumB / numPixel);
emit colorPicked(avgColor);
}
示例2: dumpFullScreen
void Screenshot::dumpFullScreen()
{
QDesktopWidget *desktop = QApplication::desktop();
originalPixmap = QPixmap();
originalPixmap = QPixmap::grabWindow(desktop->winId(), 0, 0,
desktop->width(), desktop->height());
currentPixmap = originalPixmap;
}
示例3: captureRect
QPixmap ScreenShooter::captureRect(const QRect &rect)
{
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
return QGuiApplication::primaryScreen()->grabWindow(0, rect.x(), rect.y(), rect.width(), rect.height());
#else
QDesktopWidget *desktop = QApplication::desktop();
return QPixmap::grabWindow(desktop->winId(), rect.x(), rect.y(), rect.width(), rect.height());
#endif
}
示例4: getScreenPixmap
QPixmap UBDesktopAnnotationController::getScreenPixmap()
{
QDesktopWidget *desktop = QApplication::desktop();
// we capture the screen in which the mouse is.
const QRect primaryScreenRect = desktop->screenGeometry(QCursor::pos());
QCoreApplication::flush();
return QPixmap::grabWindow(desktop->winId(), primaryScreenRect.x()
, primaryScreenRect.y(), primaryScreenRect.width(), primaryScreenRect.height());
}
示例5: createDesktopPixmap
QPixmap CScreenShotView::createDesktopPixmap()
{
#ifdef Q_OS_MAC
QPixmap pixmap = getScreenPixmap(m_desktopScreen);
#else
QDesktopWidget *pDesktoWidget = QApplication::desktop();
QPixmap pixmap = m_desktopScreen->grabWindow(pDesktoWidget->winId(),pDesktoWidget->geometry().x()
,pDesktoWidget->geometry().y(),pDesktoWidget->geometry().width(),pDesktoWidget->geometry().height());
#endif
return pixmap;
}
示例6: captureScreen
//----------------------------------------------------------------------------
void GLWidget::captureScreen()
{
//LOG_ENTER_FUNC();
QDesktopWidget *desktop = QApplication::desktop();
_screenshot = QPixmap::grabWindow(
desktop->winId(),
0, 0,
desktop->width(),
desktop->height()
);
}
示例7:
QList<QPair<QPixmap, QRect> > ScreenShooter::captureWindows(const QList<WindowHandle> &windows)
{
QDesktopWidget *desktop = QApplication::desktop();
QList< QPair<QPixmap, QRect> > result;
for(const WindowHandle &window: windows)
{
if(!window.isValid())
continue;
const QRect &windowGeometry = window.rect();
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
result.append(qMakePair(QGuiApplication::primaryScreen()->grabWindow(desktop->winId(), windowGeometry.x(), windowGeometry.y(), windowGeometry.width(), windowGeometry.height()), windowGeometry));
#else
result.append(qMakePair(QPixmap::grabWindow(desktop->winId(), windowGeometry.x(), windowGeometry.y(), windowGeometry.width(), windowGeometry.height()), windowGeometry));
#endif
}
return result;
}
示例8: main
int main(int argc, char** argv)
{
QApplication app(argc, argv);
QDesktopWidget *desktop = QApplication::desktop();
float scale = dpiScaleFactor(desktop);
qDebug() << "Scale factor" << scale;
QPixmap screenshot = QPixmap::grabWindow(desktop->winId(),
0, 0, desktop->width()*scale, desktop->height()*scale);
QFile file("screenshot.png");
file.open(QIODevice::WriteOnly);
screenshot.save(&file, "JPEG", 100);//(-1..0-100) 0 smallest lowest quality
return app.exec();
}
示例9: captureWindow
QPixmap ScreenShooter::captureWindow(WindowHandle window)
{
if(!window.isValid())
return QPixmap();
const QRect &windowGeometry = window.rect();
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
return QGuiApplication::primaryScreen()->grabWindow(0, windowGeometry.x(), windowGeometry.y(), windowGeometry.width(), windowGeometry.height());
#else
QDesktopWidget *desktop = QApplication::desktop();
return QPixmap::grabWindow(desktop->winId(), windowGeometry.x(), windowGeometry.y(), windowGeometry.width(), windowGeometry.height());
#endif
}
示例10: captureScreen
QPixmap ScreenShooter::captureScreen(int screenIndex)
{
QDesktopWidget *desktop = QApplication::desktop();
if(screenIndex < 0 || screenIndex >= desktop->screenCount())
return QPixmap();
const QRect &screenGeometry = desktop->screenGeometry(screenIndex);
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
return QGuiApplication::primaryScreen()->grabWindow(0, screenGeometry.x(), screenGeometry.y(), screenGeometry.width(), screenGeometry.height());
#else
return QPixmap::grabWindow(desktop->winId(), screenGeometry.x(), screenGeometry.y(), screenGeometry.width(), screenGeometry.height());
#endif
}
示例11: on_screenShot
void MainWindow::on_screenShot()
{
QPixmap pixmap;
QDesktopWidget *desktop = QApplication::desktop();
pixmap = QPixmap::grabWindow(desktop->winId(), pos().x(), pos().y(), frameGeometry().width(), frameGeometry().height());
QString format = "png";
QString initialPath = QDir::currentPath()+
tr("/untitled.") + format;
QString fileName = QFileDialog::getSaveFileName(this,
tr("Save As"),initialPath,
tr("%1 Files (*.%2);;All Files (*)")
.arg(format.toUpper()).arg(format));
if (!fileName.isEmpty())
pixmap.save(fileName, format.toLatin1());
}
示例12: makeScreenshot
void AppView::makeScreenshot() {
// Making screenshot
QDesktopWidget* desktop = QApplication::desktop();
QRect geo = desktop->screenGeometry(desktop->screenNumber(QCursor::pos()));
screenshot_ = QGuiApplication::primaryScreen()->grabWindow(desktop->winId(),
geo.left(),
geo.top(),
geo.width(),
geo.height());
int width = screenshot_.width(),
height = screenshot_.height();
setGeometry(0, 0, width, height);
scene_.clear();
scene_.setSceneRect(0, 0, width, height);
reinitVisibleArea();
// Background screenshot
scene_.addPixmap(screenshot_);
showFullScreen();
}
示例13: if
KSnapshot::KSnapshot(QWidget *parent, KSnapshotObject::CaptureMode mode )
: QDialog(parent), KSnapshotObject(), modified(true), savedPosition(QPoint(-1, -1))
{
// TEMPORARY Make sure "untitled" enters the string freeze for 4.6,
// as explained in http://lists.kde.org/?l=kde-graphics-devel&m=128942871430175&w=2
const QString untitled = QString(tr("untitled"));
setWindowTitle("");
grabber = new QWidget( 0, Qt::X11BypassWindowManagerHint );
// TODO X11 (Xinerama and Twinview, actually) and Windows use different coordinates for the two monitors case
//
// On Windows, there are two displays. The origin (0, 0) ('o') is the top left of display 1. If display 2 is to the left, then coordinates in display 2 are negative:
// .-------.
// | |o-----.
// | 2 | |
// | | 1 |
// ._______.._____.
//
// On Xinerama and Twinview, there is only one display and two screens. The origin (0, 0) ('o') is the top left of the display:
// o-------.
// | |.-----.
// | 2 | |
// | | 1 |
// ._______.._____.
//
// Instead of moving to (-10000, -10000), we should compute how many displays are and make sure we move to somewhere out of the total coordinates.
// - Windows: use GetSystemMetrics ( http://msdn.microsoft.com/en-us/library/ms724385(v=vs.85).aspx )
// If moving to a negative position, we need to count the size of the dialog; moving to a positive position avoids having to compute the size of the dialog
grabber->move( -10000, -10000 ); // FIXME Read above
grabber->installEventFilter( this );
QVBoxLayout *vbox = new QVBoxLayout( this );
setLayout(vbox);
mainWidget = new KSnapshotWidget();
vbox->addWidget(mainWidget);
connect(mainWidget->ok_btn, SIGNAL(clicked()), SLOT(onOkBtnClicked()));
connect(mainWidget->cancel_btn, SIGNAL(clicked()), SLOT(onCancelBtnClicked()));
connect(mainWidget->save_btn, SIGNAL(clicked()), SLOT(onSaveBtnClicked()));
connect(mainWidget->help_btn, SIGNAL(clicked()), SLOT(onHelpBtnClicked()));
connect(mainWidget->lblImage, SIGNAL(startDrag()), SLOT(slotDragSnapshot()));
connect(mainWidget->btnNew, SIGNAL(clicked()), SLOT(slotGrab()));
connect(mainWidget->comboMode, SIGNAL(activated(int)), SLOT(slotModeChanged(int)));
if (qApp->desktop()->numScreens() < 2) {
mainWidget->comboMode->removeItem(CurrentScreen);
}
mainWidget->spinDelay->setSuffix(tr(" second", " seconds"));
grabber->show();
grabber->grabMouse();
#ifdef HAVE_X11_EXTENSIONS_XFIXES_H
{
int tmp1, tmp2;
//Check whether the XFixes extension is available
Display *dpy = QX11Info::display();
if (!XFixesQueryExtension( dpy, &tmp1, &tmp2 )) {
mainWidget->cbIncludePointer->hide();
mainWidget->lblIncludePointer->hide();
}
}
#elif !defined(Q_WS_WIN)
mainWidget->cbIncludePointer->hide();
mainWidget->lblIncludePointer->hide();
#endif
setMode(KSnapshotObject::Region);
qDebug() << "Mode = " << mode;
if ( mode == KSnapshotObject::FullScreen ) {
snapshot = QPixmap::grabWindow( QApplication::desktop()->winId() );
#ifdef HAVE_X11_EXTENSIONS_XFIXES_H
if ( haveXFixes && includePointer() )
grabPointerImage(0, 0);
#endif
}
else if ( mode == KSnapshotObject::CurrentScreen ) {
qDebug() << "Desktop Geom = " << QApplication::desktop()->geometry();
QDesktopWidget *desktop = QApplication::desktop();
int screenId = desktop->screenNumber( QCursor::pos() );
qDebug() << "Screenid = " << screenId;
QRect geom = desktop->screenGeometry( screenId );
qDebug() << "Geometry = " << screenId;
snapshot = QPixmap::grabWindow( desktop->winId(),
geom.x(), geom.y(), geom.width(), geom.height() );
}
else {
setMode( mode );
switch(mode)
{
case KSnapshotObject::WindowUnderCursor:
{
setIncludeDecorations( true );
performGrab();
break;
//.........这里部分代码省略.........
示例14: performGrab
void KSnapshot::performGrab()
{
int x = 0;
int y = 0;
grabber->releaseMouse();
grabber->hide();
grabTimer.stop();
title.clear();
windowClass.clear();
if ( mode() == ChildWindow ) {
WindowGrabber wndGrab;
connect( &wndGrab, SIGNAL(windowGrabbed(QPixmap)),
SLOT(slotWindowGrabbed(QPixmap)) );
wndGrab.exec();
QPoint offset = wndGrab.lastWindowPosition();
x = offset.x();
y = offset.y();
qDebug() << "last window position is" << offset;
}
else if ( mode() == WindowUnderCursor ) {
snapshot = WindowGrabber::grabCurrent( includeDecorations() );
QPoint offset = WindowGrabber::lastWindowPosition();
x = offset.x();
y = offset.y();
// If we're showing decorations anyway then we'll add the title and window
// class to the output image meta data.
if ( includeDecorations() ) {
title = WindowGrabber::lastWindowTitle();
}
}
else if ( mode() == CurrentScreen ) {
qDebug() << "Desktop Geom2 = " << QApplication::desktop()->geometry();
QDesktopWidget *desktop = QApplication::desktop();
int screenId = desktop->screenNumber( QCursor::pos() );
qDebug() << "Screenid2 = " << screenId;
QRect geom = desktop->screenGeometry( screenId );
qDebug() << "Geometry2 = " << geom;
x = geom.x();
y = geom.y();
snapshot = QPixmap::grabWindow( desktop->winId(),
x, y, geom.width(), geom.height() );
}
else {
snapshot = QPixmap::grabWindow( QApplication::desktop()->winId() );
}
#ifdef HAVE_X11_EXTENSIONS_XFIXES_H
if (haveXFixes && includePointer()) {
grabPointerImage(x, y);
}
#endif // HAVE_X11_EXTENSIONS_XFIXES_H
if ( snapshot.isNull() )
{
mainWidget->ok_btn->setEnabled(false);
mainWidget->save_btn->setEnabled(false);
}
else
{
mainWidget->ok_btn->setEnabled(true);
mainWidget->save_btn->setEnabled(true);
}
updatePreview();
QApplication::restoreOverrideCursor();
modified = true;
updateCaption();
if (savedPosition != QPoint(-1, -1)) {
move(savedPosition);
}
show();
}
示例15: grabScreenColor
QColor Overlay::grabScreenColor(const QPoint &p)
{
QDesktopWidget *desktop = QApplication::desktop();
QPixmap pixmap = QGuiApplication::screens().at(desktop->screenNumber())->grabWindow(desktop->winId(), p.x(), p.y(), 1, 1);
QImage i = pixmap.toImage();
return i.pixel(0, 0);
}