本文整理汇总了C++中QScreen::geometry方法的典型用法代码示例。如果您正苦于以下问题:C++ QScreen::geometry方法的具体用法?C++ QScreen::geometry怎么用?C++ QScreen::geometry使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QScreen
的用法示例。
在下文中一共展示了QScreen::geometry方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: initScreens
void ScreenModel::initScreens(bool first) {
// Clear
d->geometry = QRect();
d->primary = 0;
d->screens.clear();
#ifndef USE_QT5
// set role names
QHash<int, QByteArray> roleNames;
roleNames[NameRole] = "name";
roleNames[GeometryRole] = "geometry";
// set role names
setRoleNames(roleNames);
#endif
#if 0
// fake model for testing
d->geometry = QRect(0, 0, 1920, 1080);
d->primary = 1;
d->screens << ScreenPtr { new Screen { "First", QRect(0, 0, 300, 300) } }
<< ScreenPtr { new Screen { "Second", QRect(300, 0, 1320, 742) } }
<< ScreenPtr { new Screen { "Third", QRect(1620, 0, 300, 300) } };
return;
#endif
#ifdef USE_QT5
QList<QScreen *> screens = QGuiApplication::screens();
for (int i = 0; i < screens.size(); ++i) {
QScreen *screen = screens.at(i);
// add to the screens list
d->screens << ScreenPtr { new Screen { QString("Screen %1").arg(i + 1), screen->geometry() } };
// extend available geometry
d->geometry = d->geometry.united(screen->geometry());
// check if primary
if (screen == QGuiApplication::primaryScreen())
d->primary = i;
if (first) {
// Recive screen updates
connect(screen, SIGNAL(geometryChanged(const QRect &)), this, SLOT(onScreenChanged()));
}
}
#else
// set primary screen
d->primary = QApplication::desktop()->primaryScreen();
// get screen count
int screenCount = QApplication::desktop()->screenCount();
for (int i = 0; i < screenCount; ++i) {
QRect geometry = QApplication::desktop()->screenGeometry(i);
// add to the screens list
d->screens << ScreenPtr { new Screen { QString("Screen %1").arg(i + 1), geometry } };
// extend available geometry
d->geometry = d->geometry.united(geometry);
}
#endif
emit screensChanged();
}
示例2: metric
int QWidget::metric(PaintDeviceMetric m) const
{
Q_D(const QWidget);
QScreen *screen = 0;
if (QWidget *topLevel = window())
if (QWindow *topLevelWindow = topLevel->windowHandle()) {
QPlatformScreen *platformScreen = QPlatformScreen::platformScreenForWindow(topLevelWindow);
if (platformScreen)
screen = platformScreen->screen();
}
if (!screen && QGuiApplication::primaryScreen())
screen = QGuiApplication::primaryScreen();
if (!screen) {
if (m == PdmDpiX || m == PdmDpiY)
return 72;
return QPaintDevice::metric(m);
}
int val;
if (m == PdmWidth) {
val = data->crect.width();
} else if (m == PdmWidthMM) {
val = data->crect.width() * screen->physicalSize().width() / screen->geometry().width();
} else if (m == PdmHeight) {
val = data->crect.height();
} else if (m == PdmHeightMM) {
val = data->crect.height() * screen->physicalSize().height() / screen->geometry().height();
} else if (m == PdmDepth) {
return screen->depth();
} else if (m == PdmDpiX) {
if (d->extra && d->extra->customDpiX)
return d->extra->customDpiX;
else if (d->parent)
return static_cast<QWidget *>(d->parent)->metric(m);
return qRound(screen->logicalDotsPerInchX());
} else if (m == PdmDpiY) {
if (d->extra && d->extra->customDpiY)
return d->extra->customDpiY;
else if (d->parent)
return static_cast<QWidget *>(d->parent)->metric(m);
return qRound(screen->logicalDotsPerInchY());
} else if (m == PdmPhysicalDpiX) {
return qRound(screen->physicalDotsPerInchX());
} else if (m == PdmPhysicalDpiY) {
return qRound(screen->physicalDotsPerInchY());
} else if (m == PdmDevicePixelRatio) {
return screen->devicePixelRatio();
} else {
val = QPaintDevice::metric(m);// XXX
}
return val;
}
示例3: Init
void OBSProjector::Init(int monitor, bool window, QString title)
{
QScreen *screen = QGuiApplication::screens()[monitor];
if (!window)
setGeometry(screen->geometry());
bool alwaysOnTop = config_get_bool(GetGlobalConfig(),
"BasicWindow", "ProjectorAlwaysOnTop");
if (alwaysOnTop && !window)
SetAlwaysOnTop(this, true);
if (window)
setWindowTitle(title);
show();
if (source)
obs_source_inc_showing(source);
if (!window) {
QAction *action = new QAction(this);
action->setShortcut(Qt::Key_Escape);
addAction(action);
connect(action, SIGNAL(triggered()), this,
SLOT(EscapeTriggered()));
}
savedMonitor = monitor;
isWindow = window;
}
示例4: updatePosition
void ColorPicker::updatePosition()
{
QPoint pos = QCursor::pos();
QScreen *screen = findScreenAt(pos);
if (!screen) {
qWarning() << "Could not find a screen containing" << pos;
return;
}
QRect desktopRect = screen->geometry();
QPoint newPos;
if (pos.x() + GRAB_SIZE + width() < desktopRect.width()) {
newPos.setX(pos.x() + GRAB_SIZE);
} else {
newPos.setX(pos.x() - GRAB_SIZE - width());
}
if (pos.y() + GRAB_SIZE + height() < desktopRect.height()) {
newPos.setY(pos.y() + GRAB_SIZE);
} else {
newPos.setY(pos.y() - GRAB_SIZE - height());
}
move(newPos);
WId wid = QApplication::desktop()->winId();
mPixmap = screen->grabWindow(wid, pos.x() - GRAB_SIZE / 2, pos.y() - GRAB_SIZE / 2, GRAB_SIZE, GRAB_SIZE);
update();
}
示例5: estimateQToolButtonSize
//TODO - learn about DPI and point sizes and others; now is purely written by trial and error
int Utils::estimateQToolButtonSize() {
const int MIN_SIZE = 15; //under 15 pixel should be an error
const int PIXEL_FROM_FONT_SCALE = 2;
const float POINT_FROM_FONT_SCALE = 3;
const float SCREEN_RATIO_SCALE = 0.4;
const int DEFAULT_SIZE = 35;
QFont font;
float defaultFontSize = font.pixelSize() * PIXEL_FROM_FONT_SCALE;
//increasingly desperate computations:
if (defaultFontSize <= MIN_SIZE) {
defaultFontSize = font.pointSize() * POINT_FROM_FONT_SCALE;
printf("%s - warning, trying QFont.pointSize():%f\n", __func__, defaultFontSize);
}
if (defaultFontSize <= MIN_SIZE) {
QScreen* screen = QGuiApplication::primaryScreen();
float auxFontSize = SCREEN_RATIO_SCALE * screen->geometry().width();
defaultFontSize = auxFontSize;
printf("%s - warning, screen geometry:%f\n", __func__, defaultFontSize);
}
if (defaultFontSize <= MIN_SIZE) {
defaultFontSize = DEFAULT_SIZE;
printf("%s - warning, will assume dumb size:%f\n", __func__, defaultFontSize);
}
return defaultFontSize;
}
示例6: show
void App::show()
{
QScreen *currScreen = screen();
QRect rect(0, 0, 800, 600);
rect.moveTopLeft(currScreen->geometry().topLeft());
setGeometry(rect);
showMaximized();
}
示例7: metric
/*!
\internal
*/
int QPaintDeviceWindow::metric(PaintDeviceMetric metric) const
{
QScreen *screen = this->screen();
if (!screen && QGuiApplication::primaryScreen())
screen = QGuiApplication::primaryScreen();
switch (metric) {
case PdmWidth:
return width();
case PdmWidthMM:
if (screen)
return width() * screen->physicalSize().width() / screen->geometry().width();
break;
case PdmHeight:
return height();
case PdmHeightMM:
if (screen)
return height() * screen->physicalSize().height() / screen->geometry().height();
break;
case PdmDpiX:
if (screen)
return qRound(screen->logicalDotsPerInchX());
break;
case PdmDpiY:
if (screen)
return qRound(screen->logicalDotsPerInchY());
break;
case PdmPhysicalDpiX:
if (screen)
return qRound(screen->physicalDotsPerInchX());
break;
case PdmPhysicalDpiY:
if (screen)
return qRound(screen->physicalDotsPerInchY());
break;
case PdmDevicePixelRatio:
if (screen)
return screen->devicePixelRatio();
break;
default:
break;
}
return QPaintDevice::metric(metric);
}
示例8: initScreens
void ScreenModel::initScreens(bool first) {
// Clear
beginResetModel();
d->geometry = QRect();
d->primary = 0;
d->screens.clear();
#if 0
// fake model for testing
d->geometry = QRect(0, 0, 1920, 1080);
d->primary = 1;
d->screens << ScreenPtr { new Screen { "First", QRect(0, 0, 300, 300) } }
<< ScreenPtr { new Screen { "Second", QRect(300, 0, 1320, 742) } }
<< ScreenPtr { new Screen { "Third", QRect(1620, 0, 300, 300) } };
return;
#endif
QScreen *primaryScreen = QGuiApplication::primaryScreen();
QList<QScreen *> screens = QGuiApplication::screens();
for (int i = 0; i < screens.size(); ++i) {
QScreen *screen = screens.at(i);
// heuristic to detect clone mode, in that case only consider the primary screen
if (screen->virtualGeometry() == primaryScreen->geometry() && screen != primaryScreen)
continue;
// add to the screens list
d->screens << ScreenPtr { new Screen { QStringLiteral("Screen %1").arg(i + 1), screen->geometry() } };
// extend available geometry
d->geometry = d->geometry.united(screen->geometry());
// check if primary
if (screen == QGuiApplication::primaryScreen())
d->primary = i;
if (first) {
// Recive screen updates
connect(screen, SIGNAL(geometryChanged(const QRect &)), this, SLOT(onScreenChanged()));
}
}
endResetModel();
emit primaryChanged();
}
示例9: savePosition
void MainWindow::savePosition(Qt::WindowState state) {
if (state == Qt::WindowActive) state = windowHandle()->windowState();
if (state == Qt::WindowMinimized || !positionInited()) return;
auto savedPosition = cWindowPos();
auto realPosition = savedPosition;
if (state == Qt::WindowMaximized) {
realPosition.maximized = 1;
} else {
auto r = geometry();
realPosition.x = r.x();
realPosition.y = r.y();
realPosition.w = r.width() - (_rightColumn ? _rightColumn->width() : 0);
realPosition.h = r.height();
realPosition.maximized = 0;
realPosition.moncrc = 0;
}
DEBUG_LOG(("Window Pos: Saving position: %1, %2, %3, %4 (maximized %5)").arg(realPosition.x).arg(realPosition.y).arg(realPosition.w).arg(realPosition.h).arg(Logs::b(realPosition.maximized)));
auto centerX = realPosition.x + realPosition.w / 2;
auto centerY = realPosition.y + realPosition.h / 2;
int minDelta = 0;
QScreen *chosen = nullptr;
auto screens = QGuiApplication::screens();
for (auto screen : QGuiApplication::screens()) {
auto delta = (screen->geometry().center() - QPoint(centerX, centerY)).manhattanLength();
if (!chosen || delta < minDelta) {
minDelta = delta;
chosen = screen;
}
}
if (chosen) {
auto screenGeometry = chosen->geometry();
DEBUG_LOG(("Window Pos: Screen found, geometry: %1, %2, %3, %4").arg(screenGeometry.x()).arg(screenGeometry.y()).arg(screenGeometry.width()).arg(screenGeometry.height()));
realPosition.x -= screenGeometry.x();
realPosition.y -= screenGeometry.y();
realPosition.moncrc = screenNameChecksum(chosen->name());
}
if (realPosition.w >= st::windowMinWidth && realPosition.h >= st::windowMinHeight) {
if (realPosition.x != savedPosition.x
|| realPosition.y != savedPosition.y
|| realPosition.w != savedPosition.w
|| realPosition.h != savedPosition.h
|| realPosition.moncrc != savedPosition.moncrc
|| realPosition.maximized != savedPosition.maximized) {
DEBUG_LOG(("Window Pos: Writing: %1, %2, %3, %4 (maximized %5)").arg(realPosition.x).arg(realPosition.y).arg(realPosition.w).arg(realPosition.h).arg(Logs::b(realPosition.maximized)));
cSetWindowPos(realPosition);
Local::writeSettings();
}
}
}
示例10: initialize
bool OGGameEngine::initialize()
{
qApp->installEventFilter(this);
m_window.reset(new OGWindow(m_game));
QScreen* screen = getPrimaryScreen();
int x = (screen->geometry().width() - getWidth()) / 2.0f;
int y = (screen->geometry().height() - getHeight()) / 2.0f;
m_window->setGeometry(x, y, getWidth(), getHeight());
m_window->setFixedSize(getWidth(), getHeight());
if (m_fullscreen)
{
//initialize video mode
#ifdef Q_OS_WIN32
m_isVideoModeSupported = OGVideoMode::testVideoMode(getWidth()
, getHeight());
if (m_isVideoModeSupported)
{
OGVideoMode::setVideoMode(getWidth(), getHeight());
m_window->showFullScreen();
}
else { logWarn("Video mode not supported"); }
#else
m_window->show();
#endif // Q_OS_WIN32
}
else
{
m_window->show();
}
connect(qApp, SIGNAL(aboutToQuit()), this, SLOT(gameExit()));
return true;
}
示例11: requestPixmap
QPixmap ScreenCaptureProvider::requestPixmap(const QString &/*id*/, QSize * /*size*/, const QSize& /*requestedSize*/)
{
QScreen *screen = QGuiApplication::primaryScreen();
if (screen)
{
QPixmap screenShotPixmap = screen->grabWindow(0);
qDebug() << screen->geometry();
setLastPixmap(screenShotPixmap);
return screenShotPixmap;
}
return QPixmap();
}
示例12: initialize
bool OGGameEngine::initialize()
{
QScreen* screen = QGuiApplication::primaryScreen();
window_ = new OGWindow(pGame_);
// Set fixed size of window
window_->setMaximumSize(QSize(getWidth(), getHeight()));
window_->setMinimumSize(QSize(getWidth(), getHeight()));
// Center window on screen
int x = qRound((screen->geometry().width() - getWidth()) / 2.0f);
int y = qRound((screen->geometry().height() - getHeight()) / 2.0f);
window_->setGeometry(x, y, getWidth(), getHeight());
if (fullscreen_)
{
//initialize video mode
#ifdef Q_OS_WIN32
isVideoModeSupported_ = OGVideoMode::testVideoMode(getWidth()
, getHeight());
if (isVideoModeSupported_)
{
OGVideoMode::setVideoMode(getWidth(), getHeight());
window_->showFullScreen();
}
else { logWarn("Video mode not supported"); }
#else
window_->show();
#endif // Q_OS_WIN32
}
else { window_->show(); }
return true;
}
示例13: GetScreenInfoFromNativeWindow
void GetScreenInfoFromNativeWindow(QWindow* window, blink::WebScreenInfo* results)
{
QScreen* screen = window->screen();
blink::WebScreenInfo r;
r.deviceScaleFactor = screen->devicePixelRatio();
r.depthPerComponent = 8;
r.depth = screen->depth();
r.isMonochrome = (r.depth == 1);
QRect screenGeometry = screen->geometry();
r.rect = blink::WebRect(screenGeometry.x(), screenGeometry.y(), screenGeometry.width(), screenGeometry.height());
QRect available = screen->availableGeometry();
r.availableRect = blink::WebRect(available.x(), available.y(), available.width(), available.height());
*results = r;
}
示例14: main
int main(int argc, char** argv)
{
try {
QApplication app(argc, argv);
GeneratorWindow myWindow;
QScreen* screen = app.primaryScreen();
QRect rec = screen->geometry();
myWindow.resize(rec.size().width(), rec.size().height() - 100);
myWindow.show();
return app.exec();
} catch (std::exception& e) {
std::cout << e.what() << std::endl;
}
return -1;
}
示例15: psSavePosition
void PsMainWindow::psSavePosition(Qt::WindowState state) {
if (state == Qt::WindowActive) state = windowHandle()->windowState();
if (state == Qt::WindowMinimized || !posInited) return;
TWindowPos pos(cWindowPos()), curPos = pos;
if (state == Qt::WindowMaximized) {
curPos.maximized = 1;
} else {
QRect r(geometry());
curPos.x = r.x();
curPos.y = r.y();
curPos.w = r.width();
curPos.h = r.height();
curPos.maximized = 0;
}
int px = curPos.x + curPos.w / 2, py = curPos.y + curPos.h / 2, d = 0;
QScreen *chosen = 0;
QList<QScreen*> screens = App::app()->screens();
for (QList<QScreen*>::const_iterator i = screens.cbegin(), e = screens.cend(); i != e; ++i) {
int dx = (*i)->geometry().x() + (*i)->geometry().width() / 2 - px; if (dx < 0) dx = -dx;
int dy = (*i)->geometry().y() + (*i)->geometry().height() / 2 - py; if (dy < 0) dy = -dy;
if (!chosen || dx + dy < d) {
d = dx + dy;
chosen = *i;
}
}
if (chosen) {
curPos.x -= chosen->geometry().x();
curPos.y -= chosen->geometry().y();
QByteArray name = chosen->name().toUtf8();
curPos.moncrc = hashCrc32(name.constData(), name.size());
}
if (curPos.w >= st::wndMinWidth && curPos.h >= st::wndMinHeight) {
if (curPos.x != pos.x || curPos.y != pos.y || curPos.w != pos.w || curPos.h != pos.h || curPos.moncrc != pos.moncrc || curPos.maximized != pos.maximized) {
cSetWindowPos(curPos);
Local::writeSettings();
}
}
}