Results 1 to 11 of 11

Thread: Dynamic property and stylesheets

  1. #1
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Dynamic property and stylesheets

    I need to set border color based on some dynamic property and am using the following stylesheet for the same -

    QWidget[editFocus="true"]
    {
    border: 3px solid rgb(20,15,255);
    }
    Now if I set the dynamic property 'editFocus' through designer it loads properly the first time. This is obvious.

    But when I change the value of "editFocus" through code at runtime, the color doesnt get updated. Is it the correct behaviour ?

    What I want to achieve is the border color should change on the widget having focus or edit Focus. This is similar to the edit-focus for Qt for Embedded. But since normal applications dont have such kind of behaviour, am trying to do it on my own.

  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: Dynamic property and stylesheets

    Quote Originally Posted by aamer4yu View Post
    But when I change the value of "editFocus" through code at runtime, the color doesnt get updated. Is it the correct behaviour ?
    Yes. The stylesheet needs to be reapplied if you want it to reflect changes to the variable.

    What I want to achieve is the border color should change on the widget having focus or edit Focus. This is similar to the edit-focus for Qt for Embedded. But since normal applications dont have such kind of behaviour, am trying to do it on my own.
    I don't think you can do it with dynamic properties. Create a regular property and update the stylesheet after the property value changes or react to events (reinstalling the style sheet again). An alternative is to use QPalette instead of style sheets.
    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
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Dynamic property and stylesheets

    Yes. The stylesheet needs to be reapplied if you want it to reflect changes to the variable.
    How does QWidget:focus work then ? You dont need to apply stylesheet whenever the focus changes,, Qt does that automatically.

    I don't think you can do it with dynamic properties.
    I guess we can. Because when I set the dynamic property through designer in the ui file, the style does get applied.
    Create a regular property and update the stylesheet after the property value changes or react to events (reinstalling the style sheet again).
    This is something I want to avoid, since this will involve applying stylesheet on every focus changed event at the least. I was wondering if it could be automatic like QWidget:focus stylesheet. My last option would be to subclass widgets which will give me total control.
    I wish there was some way to enable keypad navigation + edit focus stuff on desktop applications too.

    An alternative is to use QPalette instead of style sheets.
    How can I use palette to draw border color ?

  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: Dynamic property and stylesheets

    Quote Originally Posted by aamer4yu View Post
    How does QWidget:focus work then ? You dont need to apply stylesheet whenever the focus changes,, Qt does that automatically.
    It's not a dynamic property.

    I guess we can.
    So why are you asking?
    I was wondering if it could be automatic like QWidget:focus stylesheet.
    Only if you implement it.

    How can I use palette to draw border color ?
    What do you mean? Change the colour of the frame. If a particular widget has one, of course and your style supports 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.


  5. #5
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Dynamic property and stylesheets

    What do you mean? Change the colour of the frame. If a particular widget has one, of course and your style supports it.
    I mean how can we achieve the following effect with QPalette -
    "border : 3px solid blue" ??

    Well from the discussion can I assume the following -
    For style sheets involving dynamic properties, you will need to yourself re-apply the style sheet once the dynamic property changes.

    and since I want this border color based on dynamic property, how should I manage the stylesheet ? Because I have a single stylesheet file and applying the whole again might be heavy, isnt it ?

  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: Dynamic property and stylesheets

    Quote Originally Posted by aamer4yu View Post
    I mean how can we achieve the following effect with QPalette -
    "border : 3px solid blue" ??
    You can't. You can't ADD elements using QPalette, you may only modify colours of existing ones. If you want to add an extra frame to a widget then subclass it.

    Well from the discussion can I assume the following -
    For style sheets involving dynamic properties, you will need to yourself re-apply the style sheet once the dynamic property changes.
    Yes, that's correct.

    and since I want this border color based on dynamic property, how should I manage the stylesheet ? Because I have a single stylesheet file and applying the whole again might be heavy, isnt it ?
    You can reapply stylesheet on the widget only if you make sure the border is set by the widget's stylesheet and not the application stylesheet.
    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
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Dynamic property and stylesheets

    You can reapply stylesheet on the widget only if you make sure the border is set by the widget's stylesheet and not the application stylesheet.
    But I was thinking of using a single style sheet on the appliction which will handle both cases.

    How to achieve this -
    Say I have a stylesheet that says -
    QWidget[myProperty="true"] { border: 3px solid red; }
    so when my dynamic property becomes true, I apply the above stylesheet. Till here fine.
    Now when the dynamic property becomes false, what styleseheet to apply ?
    Since the border wont be same for all widgets, it will vary from pushbuttons to line edits to combo box etc.
    So what stylesheet to use so that normal border for respective widgets are drawn ?

  8. #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: Dynamic property and stylesheets

    Quote Originally Posted by aamer4yu View Post
    But I was thinking of using a single style sheet on the appliction which will handle both cases.
    You can't have them all. Life would be boring if everything was easy.

    Now when the dynamic property becomes false, what styleseheet to apply ?
    The same one.
    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.


  9. #9
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Dynamic property and stylesheets

    Quote:
    Now when the dynamic property becomes false, what styleseheet to apply ?
    The same one.
    It means border needs to be specified for all widgets to be used ? How can I use the Qt default borders ?
    I mean QLineEdit has different kind of border than QListWidget. So in my stylsheet if I write -
    QLineEdit[myProperty="true"] { border : 3px solid blue }
    QLineEdit[myProperty="false"] { border : none } // --> this will make it borderless, while I want the default Qt border for QLineEdit. What to write instead of none ?
    This applies to all other widgets.

    [btw thanks for patiently answering my queries till now ]

  10. #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: Dynamic property and stylesheets

    When you start using stylesheets, you can forget about default decorations, especially on Windows and Mac. I'm not sure what you are trying to obtain but if you just want to mark a widget that has a property set, apply an event filter on your application object and whenever you receive a paint event, draw the widget as usual but also draw a border around the widget like Designer does with layouts,
    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.


  11. #11
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Dynamic property and stylesheets

    I'm not sure what you are trying to obtain but if you just want to mark a widget that has a property set, apply an event filter on your application object and whenever you receive a paint event, draw the widget as usual but also draw a border around the widget like Designer does with layouts,
    How to draw the border ? We will receive the paint event in eventFilter, then where to draw the border ? we cant draw outside widgets. Can you show a psuedo code ?

Similar Threads

  1. StyleSheets/QTabBar -- max-width property not respected.
    By momesana in forum Qt Programming
    Replies: 1
    Last Post: 22nd November 2007, 10:25

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.