1

此代码有效:

QRect r = QApplication::desktop()->availableGeometry();
QRect main_rect = this->geometry();
main_rect.moveTopRight(r.topRight());
this->move(main_rect.topLeft()); 

此代码正在处理屏幕的位置..但我想对齐屏幕的右侧..

你有什么主意吗 ?

谢谢..

4

2 回答 2

0

I think you should use setAlignment to your main layout something like this

QHBoxLayout *mainLayout = new QHBoxLayout;
mainLayout->setAlignment(Qt::AlignRight);
于 2013-08-19T17:35:01.520 回答
0

我有一个解决方案,但遗憾的是这并不容易......

首先,您必须在短暂延迟后进行移动,您可以在此处阅读更多信息(检查接受的答案)

移动窗口所要做的如下:

void MainWindow::timerEvent(QTimerEvent *event)
{

    if(event->timerId() == this->TimerID)
    {
        event->accept();
        this->killTimer(this->TimerID);
        //Used to kill the timer that was created in the constructor, needs the ID to do this

        QRect desktopGeom = QApplication::desktop()->availableGeometry(); //Screen size
        QRect windowFrame = this->frameGeometry(); //Window with frame
        QRect windowSize = this->geometry(); //Window without frame

        int smallFrameFactor = (windowFrame.width() - windowSize.width()) / 2; //Because the left, right and bottom border have the same size
        int wideFrameFactor = windowFrame.height() - (windowSize.height() + smallFrameFactor); //The big, upper border

        int x_pos = desktopGeom.x() + desktopGeom.width() - windowSize.width() - smallFrameFactor;
        int y_pos = desktopGeom.y() + wideFrameFactor;

        this->setGeometry(x_pos, y_pos, windowSize.width(), windowSize.height());
    }
    else
        event->ignore();
}

我添加了一张图片,以可视化我在上面所做的事情。我希望我能帮助你。

编辑:刚刚看到这个问题已经有一年多了......也许它对某人仍然有帮助......

示例图像

于 2014-10-09T16:03:45.547 回答