本文整理汇总了C++中QDesktopWidget::screenNumber方法的典型用法代码示例。如果您正苦于以下问题:C++ QDesktopWidget::screenNumber方法的具体用法?C++ QDesktopWidget::screenNumber怎么用?C++ QDesktopWidget::screenNumber使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QDesktopWidget
的用法示例。
在下文中一共展示了QDesktopWidget::screenNumber方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: showEvent
void AutoExpandableDialog::showEvent(QShowEvent *e) {
// Overriding showEvent is required for consistent UI with fixed size under custom DPI
// Show dialog
QDialog::showEvent(e);
// and resize textbox to fit the text
// NOTE: For some strange reason QFontMetrics gets more accurate
// when called from showEvent. Only 6 symbols off instead of 11 symbols off.
int textW = ui->textEdit->fontMetrics().width(ui->textEdit->text()) + 4;
int screenW = QApplication::desktop()->width() / 4;
int wd = textW;
if (!windowTitle().isEmpty()) {
int _w = fontMetrics().width(windowTitle());
if (_w > wd)
wd = _w;
}
if (!ui->textLabel->text().isEmpty()) {
int _w = ui->textLabel->fontMetrics().width(ui->textLabel->text());
if (_w > wd)
wd = _w;
}
// Now resize the dialog to fit the contents
// Maximum value is whichever is smaller:
// 1. screen width / 4
// 2. max width of text from either of: label, title, textedit
// If the value is less than dialog default size default size is used
wd = textW < screenW ? textW : screenW;
if (wd > width())
resize(width() - ui->horizontalLayout->sizeHint().width() + wd, height());
// Use old dialog behavior: prohibit resizing the dialog
setFixedHeight(height());
// Update geometry: center on screen
QDesktopWidget *desk = QApplication::desktop();
MainWindow *wnd = qobject_cast<MainWindow*>(QApplication::activeWindow());
QPoint p = QCursor::pos();
int screenNum = 0;
if (wnd == 0)
screenNum = desk->screenNumber(p);
else if (!wnd->isHidden())
screenNum = desk->screenNumber(wnd);
else
screenNum = desk->screenNumber(p);
QRect screenRes = desk->screenGeometry(screenNum);
QRect geom = geometry();
geom.moveCenter(QPoint(screenRes.width() / 2, screenRes.height() / 2));
setGeometry(geom);
}
示例2: screenNumberForQWidget
void tst_QDesktopWidget::screenNumberForQWidget()
{
QDesktopWidget desktop;
QCOMPARE(desktop.screenNumber(0), 0);
QWidget widget;
widget.show();
QApplication::processEvents();
QVERIFY(widget.isVisible());
int widgetScreen = desktop.screenNumber(&widget);
QVERIFY(widgetScreen > -1);
QVERIFY(widgetScreen < desktop.numScreens());
}
示例3: 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);
}
示例4: QThread
NxClientThread::NxClientThread(QObject *parent)
: QThread(parent),
m_host(std::string()),
m_port(0),
m_privateKey(std::string()),
m_xid(0),
m_stopped(false)
{
m_client.setSessionData(&m_data);
QDesktopWidget *desktop = QApplication::desktop();
int currentScreen = desktop->screenNumber();
QRect rect = desktop->screenGeometry(currentScreen);
m_client.setResolution(rect.width(), rect.height());
m_client.setDepth(24);
m_client.setRender(true);
m_data.sessionName = "krdcSession";
m_data.cache = 8;
m_data.images = 32;
m_data.linkType = "adsl";
m_data.render = true;
m_data.backingstore = "when_requested";
m_data.imageCompressionMethod = 2;
m_data.keyboard = "defkeymap";
m_data.media = false;
m_data.agentServer = "";
m_data.agentUser = "";
m_data.agentPass = "";
m_data.cups = 0;
m_data.suspended = false;
m_data.fullscreen = false;
m_data.encryption = true;
m_data.terminate = false;
}
示例5: stop
void VisibleAreaMode::stop(int x, int y) {
toolbar_.appView().setMouseTracking(false);
move(x, y);
const int padding = 10;
QDesktopWidget *desktop = QApplication::desktop();
QRect geo = desktop->screenGeometry(desktop->screenNumber(QCursor::pos()));
// Width
int formX = area.x + area.width + 28;
int screenWidth = geo.width();
int formWidth = toolbar_.width();
if (formX + formWidth + padding > screenWidth) {
formX = screenWidth - formWidth - padding;
}
// Height
int formHeight = toolbar_.height();
int formY = area.y + area.height / 2 - formHeight / 2;
int screenHeight = geo.height();
if (formY < padding) {
formY = padding;
} else if (formY + formHeight + padding > screenHeight) {
formY = screenHeight - formHeight - padding;
}
toolbar_.setGeometry(formX, formY, formWidth, formHeight);
toolbar_.show();
}
示例6: set
void VisibleAreaMode::set(int x, int y, int width, int height) {
int sceneWidth = scene_.width(),
sceneHeight = scene_.height();
rectTop->setRect(0, 0, sceneWidth, y);
rectBottom->setRect(0, y + height, sceneWidth, sceneHeight - y - height);
rectLeft->setRect(0, y, x, height);
rectRight->setRect(x + width, y, sceneWidth - x - width, height);
QDesktopWidget *desktop = QApplication::desktop();
QRect geo = desktop->screenGeometry(desktop->screenNumber(QCursor::pos()));
int screenWidth = geo.width();
int screenHeight = geo.height();
// Horizontal and vertical lines
if (0 == width && 0 == height) {
lineTop->setLine(0, y, screenWidth, y);
lineLeft->setLine(x, 0, x, screenHeight);
return;
}
lineTop->setLine(0, y - 1, screenWidth, y - 1);
lineBottom->setLine(0, y + height + 1, screenWidth, y + height + 1);
lineLeft->setLine(x - 1, 0, x - 1, screenHeight);
lineRight->setLine(x + width + 1, 0, x + width + 1, sceneHeight);
}
示例7: 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);
}
示例8: consumeEntities
void BubbleManager::consumeEntities()
{
if (!m_currentNotify.isNull()) {
m_currentNotify->deleteLater();
m_currentNotify = nullptr;
}
if (m_entities.isEmpty()) {
m_currentNotify = nullptr;
return;
}
m_currentNotify = m_entities.dequeue();
QDesktopWidget *desktop = QApplication::desktop();
int pointerScreen = desktop->screenNumber(QCursor::pos());
int primaryScreen = desktop->primaryScreen();
QWidget *pScreenWidget = desktop->screen(primaryScreen);
if (checkDockExistence()) {
m_dockGeometry = m_dbusdockinterface->geometry();
}
if (checkControlCenterExistence())
m_ccGeometry = m_dbusControlCenter->rect();
if (checkControlCenterExistence() && pointerScreen == primaryScreen)
bindControlCenterX();
if (pointerScreen != primaryScreen)
pScreenWidget = desktop->screen(pointerScreen);
m_bubble->setBasePosition(getX(), getY(), pScreenWidget->geometry());
m_bubble->setEntity(m_currentNotify);
}
示例9: QDialog
dlgPrint::dlgPrint( QWidget* parent, CardInformation& CI_Data, GenPur::UI_LANGUAGE lng, QString const& cardTypeText)
: QDialog(parent)
, m_CI_Data(CI_Data)
, m_CurrReaderName("")
{
if (CI_Data.isDataLoaded())
{
PTEID_EIDCard* Card = dynamic_cast<PTEID_EIDCard*>(m_CI_Data.m_pCard);
ui.setupUi(this);
setFixedSize(420, 245);
const QIcon Ico = QIcon( ":/images/Images/Icons/Print.png" );
this->setWindowIcon( Ico );
QDesktopWidget* desktop = QApplication::desktop();
int screenNr = desktop->screenNumber();
QRect rect = desktop->availableGeometry(screenNr);
int height = rect.height();
int thiswidth = this->width();
int thisheight = this->height();
if (thisheight > height)
{
this->resize(thiswidth,height-20); //make sure the window fits
}
CI_Data.LoadData(*Card,m_CurrReaderName);
}
}
示例10: triggerNews
void MainWindow::triggerNews() {
if (ui->groupBox_browser->isHidden()) {
ui->statusBar->showMessage("Loading page...");
ui->webView->setUrl(newsUrl);
if (!isMaximized()) {
QDesktopWidget* mydesk = QApplication::desktop();
int screen = mydesk->screenNumber(this);
QRect screenSize = mydesk->screenGeometry(screen);
QRect windowGeometry = this->geometry();
int difference = 811 - 356;
if (windowGeometry.height() + difference + pos().y() > screenSize.bottom()) {
this->move(pos().x(), pos().y() - (windowGeometry.height() + difference + pos().y() - screenSize.bottom()));
}
this->resize(907, 811);
}
ui->actionShow_news->setText("Hide news");
//ui->actionShow_news->setChecked(true);
ui->groupBox_browser->show();
} else {
ui->groupBox_browser->hide();
if (!isMaximized())
this->resize(907, 256);
//ui->actionShow_news->setChecked(false);
ui->actionShow_news->setText("Show news");
}
}
示例11: kmenuAccelActivated
void MenuManager::kmenuAccelActivated()
{
if(m_kmenu->isVisible())
{
m_kmenu->hide();
return;
}
m_kmenu->initialize();
if(m_kbuttons.isEmpty())
{
// no button to use, make it behave like a desktop menu
QPoint p;
// Popup the K-menu at the center of the screen.
QDesktopWidget *desktop = KApplication::desktop();
QRect r = desktop->screenGeometry(desktop->screenNumber(QCursor::pos()));
// kMenu->rect() is not valid before showing, use sizeHint()
p = r.center() - QRect(QPoint(0, 0), m_kmenu->sizeHint()).center();
m_kmenu->popup(p);
// when the cursor is in the area where the menu pops up,
// the item under the cursor gets selected. The single shot
// avoids this from happening by allowing the item to be selected
// when the event loop is enterred, and then resetting it.
QTimer::singleShot(0, this, SLOT(slotSetKMenuItemActive()));
}
else
{
// We need the kmenu's size to place it at the right position.
// We cannot rely on the popup menu's current size(), if it wasn't
// shown before, so we resize it here according to its sizeHint().
const QSize size = m_kmenu->sizeHint();
m_kmenu->resize(size.width(), size.height());
PanelPopupButton *button = findKButtonFor(m_kmenu);
// let's unhide the panel while we're at it. traverse the widget
// hierarchy until we find the panel, if any
QObject *menuParent = button->parent();
while(menuParent)
{
ExtensionContainer *ext = dynamic_cast< ExtensionContainer * >(menuParent);
if(ext)
{
ext->unhideIfHidden();
// make sure it's unhidden before we use it to figure out
// where to popup
qApp->processEvents();
break;
}
menuParent = menuParent->parent();
}
button->showMenu();
}
}
示例12: setDpiFromWidget
void QKineticScroller::setDpiFromWidget(QWidget *widget)
{
Q_D(QKineticScroller);
QDesktopWidget *dw = QApplication::desktop();
QPointF dpi = d->realDpi(widget ? dw->screenNumber(widget) : dw->primaryScreen());
setDpi((dpi.x() + dpi.y()) / qreal(2));
}
示例13: glowBarOpacity
qreal TopMenuBar::glowBarOpacity()
{
QPoint cursorPos = QCursor::pos();
QDesktopWidget *desktop = QApplication::desktop();
int screen = desktop->screenNumber(cursorPos);
QRect desktopRect = desktop->availableGeometry(screen);
return 1.0 - ((cursorPos.y() - desktopRect.y())/qreal(desktopRect.height())*2.0);
}
示例14: switch
int
ScreenInfo::cornerScreen(Corner corner) const
{
QDesktopWidget* desktop = QApplication::desktop();
switch(corner) {
case TopLeft:
return desktop->screenNumber(QPoint());
case TopRight:
return desktop->screenNumber(QPoint(desktop->width(), 0));
case BottomLeft:
return desktop->screenNumber(QPoint(0, desktop->height()));
case BottomRight:
return desktop->screenNumber(QPoint(desktop->width(), desktop->height()));
default:
return desktop->screenNumber(QPoint());
}
}
示例15: QListView
ThumbnailView::ThumbnailView( QWidget* parent )
: QListView( parent )
{
QDesktopWidget *desktop = QApplication::desktop();
resize(desktop->availableGeometry(desktop->screenNumber(this)).width(), height()); //### workaround to make view layout properly on first view.
setMovement( QListView::Static );
setFrameStyle(QFrame::NoFrame);
connect( this, SIGNAL(pressed(QModelIndex)), this, SLOT(emitSelected(QModelIndex)) );
}