此代码工作:如何使主窗口到屏幕的右侧使用Qt 5.1.0
QRect r = QApplication::desktop()->availableGeometry();
QRect main_rect = this->geometry();
main_rect.moveTopRight(r.topRight());
this->move(main_rect.topLeft());
此代码工作在屏幕上的位置。但是我想对准向右的屏幕..
你有什么想法吗?
谢谢。
此代码工作:如何使主窗口到屏幕的右侧使用Qt 5.1.0
QRect r = QApplication::desktop()->availableGeometry();
QRect main_rect = this->geometry();
main_rect.moveTopRight(r.topRight());
this->move(main_rect.topLeft());
此代码工作在屏幕上的位置。但是我想对准向右的屏幕..
你有什么想法吗?
谢谢。
我认为你应该使用参考setAlignment到主布局是这样的
QHBoxLayout *mainLayout = new QHBoxLayout;
mainLayout->setAlignment(Qt::AlignRight);
我有一个解决办法,但遗憾的是它并不那么容易......
首先,你必须在短暂的延迟后做这个动作,你可以阅读更多关于它的信息here (Check the accepted answere)
你需要做的事情是移动窗口如下:
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();
}
我添加了一张图片,以图片化上面做的事情。我希望我能够帮助你。
编辑:刚刚看到这个问题是一岁......通过也许是有人还是有帮助...
是否加工.. :( – MOC89
去设计,然后点击某处MainWindow,然后在属性窗口中找到layoutDirection并将其更改为RightToLeft – dare