Results 1 to 6 of 6

Thread: Change the color of the button by clicking on it.

  1. #1
    Join Date
    Oct 2015
    Posts
    46
    Thanks
    19
    Platforms
    Windows

    Default Change the color of the button by clicking on it.

    I want change botton color, with click on it.
    like picture under.
    dokme.gif
    my code:
    Qt Code:
    1. import QtQuick 2.0
    2. import QtQuick.Controls 1.1
    3. Item {
    4. width: 100; height: 100
    5. property bool bImgChange: true
    6.  
    7. Component.onCompleted: {
    8. for (var i = 0; i < 5; i++)
    9. repeater.append({"name": i})
    10. }
    11.  
    12. Row {
    13. Repeater {
    14. model: ListModel {
    15. id: repeater
    16. }
    17.  
    18. Button {
    19. id:dokme
    20. y:20
    21. width:20
    22. height:20
    23. Text{
    24. text:name
    25. anchors.centerIn: parent
    26. }
    27.  
    28. }
    29. }
    30. }
    31. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Change the color of the button by clicking on it.

    The image looks like you want the button to change when it is pressed, not after it has been clicked.

    Can you clarify which you want?

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    ravandi (25th February 2016)

  4. #3
    Join Date
    Oct 2015
    Posts
    46
    Thanks
    19
    Platforms
    Windows

    Default Re: Change the color of the button by clicking on it.

    I want to change the color of the button.
    Of course , The button that was clicked.
    And other buttons restored.
    like picture under.
    dokme.gif

  5. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Change the color of the button by clicking on it.

    So, restating the very same information that left some questions open is helping answering these questions how?

    Cheers,
    _

  6. #5
    Join Date
    Oct 2015
    Posts
    46
    Thanks
    19
    Platforms
    Windows

    Default Re: Change the color of the button by clicking on it.

    see this code:
    Qt Code:
    1. import QtQuick 2.0
    2. import QtQuick.Controls 1.1
    3. Item {
    4. width: 100; height: 100
    5. Component.onCompleted: {
    6. for (var i = 0; i < 5; i++){
    7. repeater.append({"name": i})
    8. }
    9. }
    10.  
    11. Row {
    12. Repeater {
    13. model: ListModel {
    14. id: repeater
    15. }
    16.  
    17. Button {
    18. id:dokme
    19. y:20
    20. width:20
    21. height:20
    22. Text{
    23. text:name
    24. anchors.centerIn: parent
    25. }
    26.  
    27.  
    28. onClicked: {
    29. rang(this)
    30.  
    31. }
    32. function rang(e){
    33. this.iconSource = "b.gif"
    34. }
    35. }
    36. }
    37. }
    38. }
    To copy to clipboard, switch view to plain text mode 
    see this code.
    When the button is clicked.
    Button color changes.
    But not like that image.


    Added after 1 24 minutes:


    The problem was solved:
    Qt Code:
    1. import QtQuick 2.0
    2. import QtQuick.Controls 1.1
    3. Item {
    4. width: 100; height: 100
    5. Component.onCompleted: {
    6. for (var i = 0; i < 5; i++){
    7. repeater.append({"name": i})
    8. }
    9. }
    10.  
    11. Row {
    12. Repeater {
    13. model: ListModel {
    14. id: repeater
    15. }
    16.  
    17. Button {
    18. id:dokme
    19. y:20
    20. width:20
    21. height:20
    22.  
    23. Text{
    24. id:man
    25. color: activeFocus ? "red" : "#000000"
    26. text:activeFocus ? "<b>"+name+"</b>" : name
    27. anchors.centerIn: parent
    28. }
    29. onClicked: {
    30. man.forceActiveFocus();
    31. }
    32. }
    33. }
    34. }
    35. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by ravandi; 26th February 2016 at 08:32.

  7. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Change the color of the button by clicking on it.

    So it had nothing to do with click at all.

    Cheers,
    _

Similar Threads

  1. Draw a shape upon clicking a button
    By ZsCosa in forum Newbie
    Replies: 2
    Last Post: 22nd July 2013, 18:30
  2. Replies: 2
    Last Post: 13th November 2011, 03:30
  3. How to change text color of push button?
    By augusbas in forum Qt Programming
    Replies: 2
    Last Post: 3rd July 2009, 11:32
  4. Custom QStyle: change only tool button text color
    By Lykurg in forum Qt Programming
    Replies: 0
    Last Post: 27th February 2009, 20:55
  5. how to change backgroup color, button color and shape?
    By lzha022 in forum Qt Programming
    Replies: 10
    Last Post: 16th June 2008, 23:25

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.