Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to resize the main window again after setFixedSize



  • In my code I set fixed size for main window If i open .mp3 file,now I need to resize main window if i open another file format. how to enable resize if I open any other file format

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

  • Lifetime Qt Champion

    Hi
    It does work. check your values :)

    just tested this

    ctor
    {
      ui->setupUi(this);
      setFixedSize(300,300);
    }
    
    
    void MainWindow::on_pushButton_released()
    {
        setFixedSize(500,500);
    }
    
    

    and it goes to 500x500 when i click



  • According to your code If I set like this setFixedSize(500,500); form resize 500x500 but I need to resize my mainwindow using mouse as a default way



  • Why don't you use resize(int w, int h) function instead of setFixedSize(w,h) at the first place?


Log in to reply