Results 1 to 10 of 10

Thread: stylesheet change on changing object name

  1. #1
    Join Date
    Mar 2010
    Posts
    63
    Thanks
    6
    Qt products
    Qt4 Qt/Embedded Qt Jambi
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default stylesheet change on changing object name

    Hi,
    I applied style sheet on widget with different object name.I m changing object name of widget at run time,but stylesheet corresponding to new object name doesnot reflect on widget.I also tried update(),but no use

    Please suggest

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,690
    Thanks
    13
    Thanked 1,599 Times in 1,527 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: stylesheet change on changing object name

    I suggest you provide some actual information on what you have done, what you expected to see, and what you actually saw. All we know is that you applied style sheet to a widget.

  3. #3
    Join Date
    Mar 2010
    Posts
    63
    Thanks
    6
    Qt products
    Qt4 Qt/Embedded Qt Jambi
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: stylesheet change on changing object name

    Hi,
    I attached a sample program in which i m try to change stylesheet of widget by changing object name on clicking the button.

    Please see the code and let me know where am i woring

    Thanks
    Attached Files Attached Files

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

    Default Re: stylesheet change on changing object name

    Stylesheets are not reevaluated when properties of widgets change. The only way to force reevaluation is to reapply the stylesheet. However changing object names in the middle of the program is probably not a good thing to do in general.
    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
    Mar 2010
    Posts
    63
    Thanks
    6
    Qt products
    Qt4 Qt/Embedded Qt Jambi
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: stylesheet change on changing object name

    I have constraint to apply stylesheet only once in my project. Can u suggest other good and proper way to solve my problem.

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

    Default Re: stylesheet change on changing object name

    Quote Originally Posted by moh.gup@gmail.com View Post
    I have constraint to apply stylesheet only once in my project. Can u suggest other good and proper way to solve my problem.
    Don't use stylesheets.
    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. #7
    Join Date
    Mar 2010
    Posts
    63
    Thanks
    6
    Qt products
    Qt4 Qt/Embedded Qt Jambi
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: stylesheet change on changing object name

    Please suggest any alternative?

  8. #8
    Join Date
    Mar 2012
    Location
    India
    Posts
    102
    Thanks
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: stylesheet change on changing object name

    Yes. Do it from your program. Apply the effects first then when the desired button is clicked, override its click event and in that change the effects of the widget again.

    This way you will even not need to change the object name of the widget from inside the program.

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

    Default Re: stylesheet change on changing object name

    Quote Originally Posted by moh.gup@gmail.com View Post
    Please suggest any alternative?
    I don't know what you are trying to do so it is hard to suggest an alternative. Subclassing QStyle is a likely solution however changing an object property will still not trigger a redraw automatically. If you are using stylesheets then reapplying the stylesheet seems the best option.
    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. #10
    Join Date
    Aug 2010
    Posts
    1
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: stylesheet change on changing object name

    Quote Originally Posted by moh.gup@gmail.com View Post
    Hi,
    I applied style sheet on widget with different object name.I m changing object name of widget at run time,but stylesheet corresponding to new object name doesnot reflect on widget.I also tried update(),but no use

    Please suggest
    after changing object name just call setStyleSheet("")

    Qt Code:
    1. label->setObjectName("errorLabel");
    2. label->setStyleSheet("");
    To copy to clipboard, switch view to plain text mode 

    this will update stylesheet for this widget

Similar Threads

  1. stylesheet not changing on Symbian^3 device
    By Ceaser88 in forum Qt for Embedded and Mobile
    Replies: 2
    Last Post: 1st August 2011, 12:55
  2. QTabBar stylesheet references (changing base color)
    By NoMa in forum Qt Programming
    Replies: 13
    Last Post: 4th April 2011, 10:49
  3. Change Stylesheet Using Dynamic Property
    By stefanadelbert in forum Qt Programming
    Replies: 4
    Last Post: 26th August 2010, 08:48
  4. Change stylesheet
    By leoalvesmachado in forum Newbie
    Replies: 0
    Last Post: 28th July 2010, 21:20
  5. Replies: 2
    Last Post: 12th April 2007, 12:11

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.