简体   繁体   中英

How to set enable resize the main window again after setFixedSize

In my code I set the fixed size for the main window If I open .mp3 file, now I need to resize the main window if I open another file format. how to enable resize if I open any other file format.I tried this: this->setFixedSize(this->sizeHint()); but not working

this is my code.

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. 
    }
}

To make the window resizable again, try this:

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
}

If you want it to be the size it was before setting fixed size, have a QSize private member in your class

private:
  QSize size_reset;

and use it to save the window size before setting it to fixed:

size_reset = this->size();
this->setFixedSize(648,425);

then to reset the window size:

setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
setMinimumSize(0,0);
this->resize(reset_size);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM