Results 1 to 17 of 17

Thread: Update GUI from Config File

  1. #1
    Join Date
    Jun 2013
    Posts
    31
    Thanks
    8
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Update GUI from Config File

    Hi,
    I am making a GUI in which based on user login a certain number of buttons are supposed to be enabled and the rest disabled. I have to do this with the help of a config file.
    Can anyone please share any examples or references if they know.
    Thank you

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Update GUI from Config File

    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jun 2013
    Posts
    31
    Thanks
    8
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Update GUI from Config File

    I have already had a look at it. I got how to read from ini files and set settings for color and all. However I am not able to understand how to apply the logic for buttons. For eg. In telkon every button has a hexadecimal argument which decides which property of the button is to be changed. Is their anything similar in Qt?

    Thank You

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Update GUI from Config File

    Properties in Qt are referenced by their names. You can use a generic QObject::setProperty() call to modify any available property.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Jun 2013
    Posts
    31
    Thanks
    8
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Update GUI from Config File

    I am trying QSettings now. I am following the following approach. I have taken two buttons and I am trying to enable and set style sheet of button 1 when I click button 2.

    [button]

    button1 = 1;
    stylesheet = background-color:green;

    And in the button 2 click slot

    QSettings settings("/root/config.ini",QSettings::IniFormat);
    settings.beginGroup("button);
    button1->setEnabled(settings.value("button1").toBool());
    button1->setStylesheet(settings.value("stylesheet").toStri ng());

    But this doesn't seem to be working. Where am I going wrong?

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Update GUI from Config File

    What exactly "does not seem to be working"? Are the values from the settings file read correctly? Are the property values set correctly? Do they contain correct or incorrect values? Have you checked all that?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. The following user says thank you to wysota for this useful post:

    SiddhantR (18th September 2013)

  8. #7
    Join Date
    Jun 2013
    Posts
    31
    Thanks
    8
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Update GUI from Config File

    Actually the enable disable part is work. I am not able to setStylesheet using the above method.
    Thanks for the reply.

  9. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Update GUI from Config File

    You mean that after a call to setStylesheet(), a call to stylesheet() returns the old value?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #9
    Join Date
    Jun 2013
    Posts
    31
    Thanks
    8
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Update GUI from Config File

    Yes the stylesheet doesn't show the color change.

  11. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Update GUI from Config File

    Could you run this code and show us the output?

    Qt Code:
    1. qDebug() << "Initial:" << button1->stylesheet();
    2. qDebug() << "To be set:" << settings.value("stylesheet").toString();
    3. button1->setStylesheet(settings.value("stylesheet").toString());
    4. qDebug() << "After change:" << button1->stylesheet();
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  12. #11
    Join Date
    Jun 2013
    Posts
    31
    Thanks
    8
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Update GUI from Config File

    Still no change

  13. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Update GUI from Config File

    Still no change to what? What is the output of the code I told you to run?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  14. The following user says thank you to wysota for this useful post:

    SiddhantR (18th September 2013)

  15. #13
    Join Date
    Jun 2013
    Posts
    31
    Thanks
    8
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Update GUI from Config File

    The button doesnt change the background color to green. And the output is
    Initial: ""
    To be set: ""
    After Chane: ""

  16. #14
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Update GUI from Config File

    So if you change an empty string to an empty string the string is still empty. That's not very surprising, is it?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  17. #15
    Join Date
    Jun 2013
    Posts
    31
    Thanks
    8
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Update GUI from Config File

    Ohhh Is it because it is considering the part after ':' in stylesheet as comment? Can you suggest me what can be done?

  18. #16
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Update GUI from Config File

    I don't know what "it" considers. I know that you're setting an empty string as the stylesheet therefore probably your code for reading the settings is incorrect.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  19. The following user says thank you to wysota for this useful post:

    SiddhantR (18th September 2013)

  20. #17
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Update GUI from Config File

    Quote Originally Posted by SiddhantR View Post
    Ohhh Is it because it is considering the part after ':' in stylesheet as comment? Can you suggest me what can be done?
    Surely if it were doing that the style sheet would be set to "background-color" but your output tells us it is being set to an empty string.

    The semi-colon, i.e. ';' not ':', is a comment introducer in INI files. If you need to embed semi-colons in strings then you need to quote them.

Similar Threads

  1. Qt Application and config File?
    By snakemedia in forum Qt Programming
    Replies: 1
    Last Post: 27th February 2011, 08:12
  2. Synchronize a config file handled QSettings on SMB
    By nightghost in forum Qt Programming
    Replies: 4
    Last Post: 26th March 2010, 08:38
  3. QSettings, my own format of config-file
    By IPFreely in forum Qt Programming
    Replies: 2
    Last Post: 14th November 2007, 20:07
  4. config file class
    By feizhou in forum Qt Programming
    Replies: 2
    Last Post: 23rd November 2006, 07:49
  5. Config file parsing
    By Vash5556 in forum Qt Programming
    Replies: 2
    Last Post: 10th September 2006, 23:11

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.