From 10:00 CET Friday 22nd November we will adjust how the server works to deal with some recently reported problems. Therefore there may be a load problem, if you experience more problems than usual trying to access the forum then please PM AndyS or any of the moderators so they can inform me.


QWidget resize not restoring window size



  • I copied these read & write routines from the QSettings doc

    void Widget::write_settings ( void )
    {
      QSettings settings ( "Daiajo" , "Combo" ) ;
    
      settings . beginGroup ( "Window" ) ;
      settings . setValue ( "Size" , size () ) ;
      settings . setValue ( "Position" , pos () ) ;
    QTextStream out ( stdout ) ;
    out << "Height = " << size () . height () << " Width = " << size () . width () << endl ;
      settings . endGroup () ;
      settings . setValue ( "Linux/Selection" , text_label -> text () ) ;
    }
    
    void Widget::read_settings ( void )
    {
      QSettings settings ( "Daiajo" , "Combo" ) ;
    
      settings . beginGroup ( "Window" ) ;
      resize ( settings . value ( "Size" , QSize ( 400 , 400 ) ) . toSize () ) ;
      move ( settings . value ( "Position" , QPoint ( 200 , 200 ) ) . toPoint () ) ;
    QTextStream out ( stdout ) ;
    out << "Height = " << size () . height () << " Width = " << size () . width () << endl ;
      settings . endGroup () ;
      text_label -> setText ( settings . value ( "Linux/Selection" , "Gentoo" ) . toString () ) ;
    }
    
    

    The Window/Position and Linux/Selection are being restored, but the Window/Size isn't. The output lines I put show that the new size of the window is being saved and restored, but the window on the screen is always 150,250; not the 200,200 default, not the saved value. Width wise the window fits the 2 widgets, but height wise its way too big. (Not sure how to get the window image in. Its just a comboBox and Label in a Hlayout.)

    So what extra do I need to do to make the window return to whatever size they made it?

    Also I can't find the settings file. I haven't specified any location information, so I was expecting ~/.config/Daiajo/Combo or something in the working directory. I also looked in /etc/xdg without finding anything.


  • Qt Champions 2018

    @Daiajo
    What type is your Widget class? Is it your main window?

    As stated in QSettings documentation:
    "On Unix systems, if the file format is NativeFormat, the following files are used by default:
    $HOME/.config/MySoft/Star Runner.conf (Qt for Embedded Linux: $HOME/Settings/MySoft/Star Runner.conf)
    $HOME/.config/MySoft.conf (Qt for Embedded Linux: $HOME/Settings/MySoft.conf)
    for each directory <dir> in $XDG_CONFIG_DIRS: <dir>/MySoft/Star Runner.conf
    for each directory <dir> in $XDG_CONFIG_DIRS: <dir>/MySoft.conf
    "



  • @jsulm Ah its not my main window, that may be the problem
    I looked in all those locations without finding settings.



  • Was my mistake, I had a line in the mainline after creating the main widget which resized it to the 150,250 value.
    I hardly look at the mainline, so didn't notice it.
    As to the settings location I no longer need it, has to be somewhere.



  • /home/user/daiajo/.config/Daiajo/Combo.conf
    

    Found them there.


Log in to reply