![](/img/trans.png)
[英]How to minimize a frameless window which has been set size to fixed by method setFixedSize in Qt?
[英]How to set enable resize the main window again after setFixedSize
在我的代碼中,我為主窗口設置了固定大小如果我打開.mp3文件,現在我需要調整主窗口的大小,如果我打開另一種文件格式。 如果我打開任何其他文件格式如何啟用調整大小。我試過這個: this->setFixedSize(this->sizeHint());
但沒有工作
這是我的代碼。
void MainWindow::on_actionOpen_triggered()
{
QString filename= QFileDialog::getOpenFileName(this,"Open Folder","","Open a File(*.*)");
on_actionStop_triggered();
player->setMedia(QUrl::fromLocalFile(filename));
on_actionPlay_triggered();
if(filename.endsWith(".mp3")){
qDebug() << " file is mp3";
this->setFixedSize(648,425);
}else{
this->setFixedSize(this->sizeHint()); //this not working.
}
}
要使窗口再次調整大小,請嘗試以下操作:
if(filename.endsWith(".mp3")){
qDebug() << " file is mp3";
this->setFixedSize(648,425);
}else{
setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
setMinimumSize(0,0);
//now you should be able to resize it
}
如果您希望它在設置固定大小之前的大小,請在您的班級中擁有一個QSize私有成員
private:
QSize size_reset;
並在將其設置為固定之前使用它來保存窗口大小:
size_reset = this->size();
this->setFixedSize(648,425);
然后重置窗口大小:
setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
setMinimumSize(0,0);
this->resize(reset_size);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.