Gamma
Gamma

Reputation: 347

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

Upvotes: 1

Views: 345

Answers (1)

p-a-o-l-o
p-a-o-l-o

Reputation: 10047

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);

Upvotes: 4

Related Questions