此代碼工作:如何使主窗口到屏幕的右側使用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