Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QWidget resize not restoring window size
Forum Updated to NodeBB v4.3 + New Features

QWidget resize not restoring window size

Scheduled Pinned Locked Moved Solved General and Desktop
qsettingslinux
5 Posts 2 Posters 1.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Daiajo
    wrote on 12 Jul 2018, 01:13 last edited by
    #1

    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.

    J 1 Reply Last reply 12 Jul 2018, 04:25
    0
    • D Daiajo
      12 Jul 2018, 01:13

      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.

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 12 Jul 2018, 04:25 last edited by
      #2

      @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
      "

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      D 1 Reply Last reply 12 Jul 2018, 05:28
      0
      • J jsulm
        12 Jul 2018, 04:25

        @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
        "

        D Offline
        D Offline
        Daiajo
        wrote on 12 Jul 2018, 05:28 last edited by
        #3

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

        D 1 Reply Last reply 12 Jul 2018, 05:33
        0
        • D Daiajo
          12 Jul 2018, 05:28

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

          D Offline
          D Offline
          Daiajo
          wrote on 12 Jul 2018, 05:33 last edited by
          #4

          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.

          D 1 Reply Last reply 12 Jul 2018, 05:36
          0
          • D Daiajo
            12 Jul 2018, 05:33

            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.

            D Offline
            D Offline
            Daiajo
            wrote on 12 Jul 2018, 05:36 last edited by
            #5
            /home/user/daiajo/.config/Daiajo/Combo.conf
            

            Found them there.

            1 Reply Last reply
            0

            4/5

            12 Jul 2018, 05:33

            • Login

            • Login or register to search.
            4 out of 5
            • First post
              4/5
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved