dimanche 21 juillet 2019

How to Check all items in a QLlistWidget?

I have a QListWidget with items that have a checkbox, I want to iterate throiugh all of them and mark them checked, I tried this:

void ScaperDialog::CheckAll(void) {
    dbg_prnt << "inside " << __func__ <<std::endl;
    QListWidget *list = parentWidget()->findChild<QListWidget *>();
    if (!list)
        std::cerr << "No QListWidget found" << std::endl;

    QList<QListWidgetItem *> items = list->findChildren<QListWidgetItem *>();
    QList<QListWidgetItem *>::iterator i;
    for (i = items.begin();i != items.end(); i++) {
        dbg_prnt << (*i)->text.ToString() << std::endl;
    }
}

but get a compiler error: error: ‘i.QList::iterator::operator*()->QListWidgetItem::text’ does not have class type dbg_prnt << (*i)->text.ToString() << std::endl; this obviously is only to print each element, to get it marked, I would do (*i)->setChecked(true); instead of printing it but I think this will give me the same error.

How do I get this rolling?




vendredi 19 juillet 2019

Lock a cell based on another cell's entry

I am building an inspection sheet in Google Sheets and have a column with check box for fail and a column with check box for pass.

How do I lock one cell when the other is checked to not allowed double checking.




Storing the value of a dynamic checkbox into the state hook

I have a form component that displays all the contacts in a stateful array as checkbox options. when the associated checkbox is checked, the contact should be passed into newGroup.groupContacts, and likewise should be removed if unchecked. What would the syntax be for including performing this action within handleCheckbox?

const CreateGroupForm = props => {

    const defaultForm = { id: null, groupName: '', groupContacts: [] }

    const [newGroup, setNewGroup] = useState(defaultForm)

    const handleInputChange = event => {
        const { name, value } = event.target 
        setNewGroup({ ...newGroup, [name]: value })
    }

    const handleCheckbox = event => {
        console.log('called')
        const {value} = event.target
        console.log(event.target)
        setNewGroup({...newGroup, groupContacts: [...newGroup.groupContacts, value] })

    }

    const handleSubmit = event => {
        event.preventDefault()

        if (!newGroup.groupName || !newGroup.groupContacts) return

        props.addGroup(newGroup)

        setNewGroup(defaultForm)

    }

    return (
        <div>
            <h2>Create a Group</h2>
            <Form onSubmit={handleSubmit}>
                <Form.Group >
                    <Form.Label>Group Name</Form.Label>
                    <Form.Control 
                        type="text" 
                        name="firstName" 
                        onChange={handleInputChange} 
                        placeholder="First Name" 
                        value={newGroup.name} 
                    />
                </Form.Group>
                <Form.Group >
                {props.contacts.map(contact => (
                    <div className="mb-3" key={contact.id}>
                        <Form.Check 
                            onChange={handleCheckbox}
                            type='checkbox'
                            label={`${contact.firstName} ${contact.lastName}`}
                            value={contact}
                        />
                    </div>
                ))}
                </Form.Group>
                <Button type="submit">Submit</Button>
                <Button>Cancel</Button>
            </Form>
        </div> 
    )
}

export default CreateGroupForm




How to insert Checkbox value to database two columns

I need one checkbox data to send to the database.

table name "status"

the column name "inline"

the column name "offline"

when the checkbox is checked it should insert "IN" into column "IN"

when the checkbox is unchecked it should insert "OUT" into column "OUT"

Thanks! enter image description here

view

                        <div class="form-group">                        
                         <div class="col-md-10">                       
            <input type="checkbox" checked data-toggle="toggle" data-on="IN" data-off="OUT">             
                    </div>
                    </div>

controller

         public function updateStatu(){
    $this->load->model('Status_Board_Model');

    $statuid = $this->input->post('statuid');
    $data = array(
        'online' => $this->input->post('online'),
        'offline' => $this->input->post('offline'),
        'comment' => $this->input->post('comment'),
    );

$this->Status_Board_Model->updateStatu( $statuid, $data);

echo json_encode(array("status" => TRUE)); }




I need a button on my home page tab that can clear all the checkboxes

I have about 15 tabs in a spreadsheet that have checkboxes in Column A.




Using :checked pseudo selector multiple times for "checkbox hack"

I am trying to use "Checkbox hack" to move and change multiple items in page's header. Only one item (div section with paragraph, links, svgs) is changed by css pseudo class :checked when input is trigerred. The logo svg, doesn't rotate after :checked .

````CSS
.menu-logo-closed{
position: absolute;
width: 29.03px;
height: 31.24px;
top: 28.45px;
right: 8%;
display: block;
transform: rotate(-183deg);
z-index: 2;
cursor: pointer;}

.section{
opacity:0;
pointer-events: none;
position: absolute;}

.section__checkbox:checked ~ .menu-logo-closed{
transform: rotate(-2.33deg);} /*:checked does nothing here */

.section__checkbox:checked ~ .section{
opacity: 1;
pointer-events: all; /*this section works*/
position: relative;} 

````HTML
<input id="header" class="section__checkbox" type="checkbox" >
        <label for="header">
        <svg viewBox="0 0 33 35" fill="none" xmlns="http://www.w3.org/2000/svg"  alt="meniu" class="menu-logo-closed">
            <path d="M1.93321 15.5657L9.20397 32.8459C9.44027 33.3771 10.4306 33.3385 10.6249 32.7906L14.9413 19.6076C15.3642 18.2852 17.7754 18.1913 18.2999 19.4768L23.6732 32.3275C23.9095 32.8587 24.8998 32.8201 25.0941 32.2722L30.913 14.4823" stroke="white" stroke-miterlimit="10"/>
            <path d="M1.66081 8.57102L8.93161 25.8523C9.16786 26.3822 10.1582 26.3436 10.3525 25.797L14.6702 12.6465C15.0932 11.3272 17.5045 11.2334 18.0288 12.5157L23.4008 25.3338C23.6371 25.8637 24.6274 25.8251 24.8218 25.2785L30.6423 7.53231" stroke="white" stroke-miterlimit="10"/>
            <path d="M1.38844 1.57633L8.62131 17.8833C8.85639 18.3833 9.84672 18.3447 10.0422 17.828L14.388 5.39759C14.8138 4.15066 17.225 4.05676 17.7465 5.26681L23.0904 17.3623C23.3255 17.8623 24.3159 17.8237 24.5114 17.307L30.3698 0.532639" stroke="white" stroke-miterlimit="10"/>
            </svg></label>
        <div  class="section">
        <p class="p-first">Lorem ipsum
        </p>strong text




When a checkBox is selected, how do I get the text that is assigned to it using e.getStateChanged?

When a checkbox is selected, (using the e.getStateChange()) I want to be able to add the checkboxes text value to an arrayList.

I currently have it that when I press a button on screen, it searches through all checkboxes (around 50 of them) and uses

if (n.isSelected())
{
    arrayList.add(n.getText());
}

Can I have it that when the checkbox is initially selected it will add that items text value, and only that item to the arrayList without having to loop through all of the checkboxes? e.g. something similar to above (but correct) such as

if(e.getStateChange() == ItemEvent.SELECTED)
{
    arrayList.add(getText());
}

If this is possible, is it then possible to then remove the relevant item from the arrayList when the checkbox is subsequently deselected?

I'm new to java so please accept my apologies if this is a daft question!