Results 1 to 4 of 4

Thread: Very basic question on how to setup a QT quick checkbox.

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2011
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    1

    Default Very basic question on how to setup a QT quick checkbox.

    I am new to QT quick and am having difficulty understanding the basic sequence of how items are executed. Sorry if the question is so basic. I have worked my way through an example that has the date/time and weather information. The top level item is a Rectangle and it has a bool property called forceOffline. Now this property can be changed by either a Config button which brings up a dialog set of checkboxes (one of which modifies it) or a single button at the top level.
    My problem is that if I tick the checkbox to change the forceOffline property and then use the single button to switch back and then go back to the dialog the checkbox remains checked. Sorry if I have not made this very clear. Below I have my checkbox item
    Qt Code:
    1. import QtQuick 2.3
    2.  
    3. Item {
    4. id: root
    5. property bool checked: true
    6. width: checkBox.width
    7. height: checkBox.height
    8.  
    9. Image {
    10. id: checkBox
    11. source: root.checked ?
    12. "../../content/resources/checkbox.png" :
    13. "../../content/resources/draw-rectangle.png"
    14. Keys.onPressed: {
    15. if (event.key == Qt.Key_Return ||
    16. event.key == Qt.Key_Enter ||
    17. event.key == Qt.Key_Space)
    18. root.checked = !root.checked;
    19. }
    20. MouseArea {
    21. anchors.fill: parent
    22. onClicked: {
    23. root.checked = !root.checked;
    24. }
    25. }
    26. }
    27. }
    To copy to clipboard, switch view to plain text mode 
    I use code like
    Qt Code:
    1. CheckBox {
    2. id: offlineCheckBox
    3. checked: root.forceOffline
    4. KeyNavigation.up: secondsCheckBox
    5. KeyNavigation.down: locationTextInput
    6. }
    To copy to clipboard, switch view to plain text mode 
    to create an instance of the Checkbox. I thought that the binding of "checked: root.forceOffline" would ensure that the checkbox was correctly ticked or not depending on its boolean state. Can anybody help me understand this?
    AS another quick question, when dealing with ordinary QT C++ you can always add a diagnostic to discover the current status of a variable. Not sure how you do this in QT quick..the closest I seem to be able to do is to do things like:
    Qt Code:
    1. onForceOfflineChanged: {
    2. console.log ("onForceOfflineChanged= " + forceOffline)
    3.  
    4. }
    To copy to clipboard, switch view to plain text mode 
    QT Quick is very different to what I have been used to.

    Thank you for reading this.
    Last edited by anda_skoa; 1st September 2015 at 21:52. Reason: changed [quote] to [code]

Similar Threads

  1. Basic Qt Sql Question
    By sidenelen in forum Newbie
    Replies: 8
    Last Post: 31st March 2012, 13:47
  2. basic C++ question
    By Maluko_Da_Tola in forum Newbie
    Replies: 3
    Last Post: 24th August 2010, 08:29
  3. very basic Qt/c++ question
    By Maluko_Da_Tola in forum Newbie
    Replies: 2
    Last Post: 25th July 2010, 14:02
  4. A few basic question
    By salmanmanekia in forum Newbie
    Replies: 12
    Last Post: 17th June 2010, 07:46
  5. Basic question
    By giacomelli.fabio in forum Newbie
    Replies: 4
    Last Post: 18th December 2009, 00:12

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
  •  
Qt is a trademark of The Qt Company.