Results 1 to 3 of 3

Thread: ExclusiveGroup in Button

  1. #1
    Join Date
    Jul 2013
    Posts
    33
    Qt products
    Qt3
    Platforms
    Unix/X11

    Post ExclusiveGroup in Button

    Hi
    I just need some hands on this as i am struggling to overcome.Here is my requirement.I have four buttons in a row loaded with images by default.Up on clicking the button i am loading one more image.All these are fine.But i need to get back to default image on button 1 wen i click on second button and new image on second button should appear.I came across Exclusive group in qml which is similar to QButtonGroup in Qt.But i could not draw the functionality out of it? can anybody help on this?

    Qt Code:
    1. Here is my sample
    2.  
    3. ExclusiveGroup{
    4. id: excGroup
    5. }
    6. ButtonImage{
    7. id: homeImage
    8. anchors { left: parent.left;}
    9. btnImageSelected: "qrc:/Images/home_active.png"
    10. btnImageNormal: "qrc:/Images/home.png"
    11. btnHeight: 100
    12. btnWidth: 130
    13. btnGroup: excGroup[/COLOR]
    14. }
    15.  
    16. ButtonImage{
    17. id: servicesImage
    18. anchors { left: parent.left;leftMargin: 140}
    19. btnImageSelected: "qrc:/Images/services_active.png"
    20. btnImageNormal: "qrc:/Images/services.png"
    21. btnHeight: 100
    22. btnWidth: 130
    23. btnGroup: excGroup
    24. }
    To copy to clipboard, switch view to plain text mode 


    Thanks in Advance

  2. #2
    Join Date
    Oct 2014
    Posts
    104
    Thanks
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: ExclusiveGroup in Button

    I suggest to create an alias for the image source and add another bool property (example selected) which will handle the change of image source, default value is false. And use the clicked signal of ButtonImage to change the selected property value.

    Qt Code:
    1. ButtonImage{
    2. id: homeImage
    3. anchors { left: parent.left;}
    4. source: selected ? "qrc:/Images/home_active.png" : "qrc:/Images/home.png"
    5. btnHeight: 100
    6. btnWidth: 130
    7.  
    8. onClicked: selected = !selected
    9.  
    10. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by joko; 27th April 2015 at 17:50.

  3. #3
    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: ExclusiveGroup in Button

    This is the easiest solution:

    javascript Code:
    1. Item {
    2. id: root
    3. property Item currentItem: null
    4.  
    5. Image {
    6. source: root.current = this ? "selected" : "normal"
    7. MouseArea { anchors.fill: parent; onClicked: root.currentItem = parent }
    8. }
    9.  
    10. Image {
    11. source: root.current = this ? "selected" : "normal"
    12. MouseArea { anchors.fill: parent; onClicked: root.currentItem = parent }
    13. }
    14. }
    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.


Similar Threads

  1. Replies: 2
    Last Post: 26th April 2011, 11:44
  2. Changing text of button in no relation to button
    By Sabre Runner in forum Newbie
    Replies: 22
    Last Post: 23rd September 2010, 12:29
  3. Replies: 6
    Last Post: 21st August 2010, 21:09
  4. Replies: 1
    Last Post: 2nd August 2010, 05:40
  5. Custom widget: a button within a button
    By Gnurou in forum Qt Programming
    Replies: 7
    Last Post: 18th June 2009, 09:03

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.