Searching for appropriate element



  • Hi hi !
    I'd like to display 2 lines of 3 QString each and make some of those QString alterable (only by clicking a character of that QString and modify it) and some others not.

    For now, i'm building a big QString and simply displaying it in a TextArea which makes the code behind awfull.
    Does someone have an idea that could fit my needs ? Using QString or not ?

    I'd love something like that :
    read-only ------------ alterable by clicking a character and then modify it with a keyboard input
    00000000 ------------ BF BD 6C 75 6A 68 00 67 ------------ a b c d e f g h
    00000008 ------------ 62 63 64 72 6C EF 00 00 ------------ i j k l m n o p

    Those ain't the real values but no minds.

    There's probably a really basic and clean solution to this but i can't find it... Qt got a pretty big doc.


  • Qt Champions 2017

    @Sillimon

    I'd say you are searching for a QTableWidget.



  • @aha_1980 said in Searching for appropriate element:

    @Sillimon

    I'd say you are searching for a QTableWidget.

    It means that i should have one column for each "editable cell" ?
    That would be between 13 and 25 columns.
    But it has a bunch of really useful properties though...

    I think i'm searching too far when it's just that simple.
    I'm trying it, thank you again !


  • Qt Champions 2017

    @Sillimon said in Searching for appropriate element:

    It means that i should have one column for each "editable cell" ?
    That would be between 13 and 25 columns.

    That depends on your needs. Maybe you just need three columns, each containing the string?



  • @aha_1980
    Yeah...
    Actually, i can't do it as i thought, using a lot of columns. The design won't fit.

    Using TableView with 3 Columns of String would be the best option but I'm now wondering how i can check user entries...
    I'm trying an event on DataChanged inside the model.


  • Qt Champions 2017

    Hi @Sillimon

    (If your model get's a bit more complex, you should have a look at QTableView and your own model implementation instead using QTableWidget)

    Regarding the user entries: that's usually done with a QInputValidator, which forbids entering invalid values (before the data is changed at all).



  • @aha_1980 said in Searching for appropriate element:

    Hi @Sillimon

    Hi hi !

    (If your model get's a bit more complex, you should have a look at QTableView and your own model implementation instead using QTableWidget)

    Yeah, i'm already using QTableView since i didn't learn to work on C++ side yet.
    I changed my methods and i'm building vectors of QString (each "line" being an vector's index value).
    I'm even taking in count latin-1 char (thanks again to you and the others for explanations) this way :

    m_alpha.clear();
        QString alpha;
        if(m_chip->getCardType() == "Mifare4K")
        {
            for (size_t i = 0; i < 8; ++i)
            {
                const QChar c = QLatin1Char(readData.at(i));
                if(c.isPrint())
                {
                    alpha.push_back(c);
                    alpha.append(" ");
                }
                else
                {
                    alpha.append(". ");
                }
            }
            m_alpha.push_back(alpha);
            alpha = "";
    
            for(size_t i = 8; i < 16; i++)
            {
                const QChar c = QChar::fromLatin1(readData.at(i));
                if(c.isPrint())
                {
                    alpha.push_back(c);
                    alpha.append(" ");
                }
                else
                {
                    alpha.append(". ");
                }
            }
            m_alpha.push_back(alpha);
        }
        else if(m_chip->getCardType() == "ISO15693")
        {
            for (size_t i = 0; i < 4; ++i)
            {
                const QChar c = QLatin1Char(readData.at(i));
                if(c.isPrint())
                {
                    alpha.push_back(c);
                    alpha.append(" ");
                }
                else
                {
                    alpha.append(". ");
                }
            }
            m_alpha.push_back(alpha);
        }
        else
        {
            m_alpha.push_back("Invalid chip");
        }
    

    On QML side, i build it this way :

    QML mouseArea.onClicked :
    tvmodel.append({hexdump: readWrite.getHexdumpLine(1), hexa: readWrite.getHexaLine(1), alpha: readWrite.getAlphaLine(1)})
    if(Card.getCardType() === "Mifare4K")
    {
            tvmodel.append({hexdump: readWrite.getHexdumpLine(2), hexa: readWrite.getHexaLine(2), alpha: readWrite.getAlphaLine(2)})
    }
    
    .cpp :
    QString ReadWrite::getAlphaLine(int line)
    {
        QString alpha;
        alpha = m_alpha.at(line-1);
        return alpha;
    }
    

    I now have something good in display !
    Currently working on writing side.

    Regarding the user entries: that's usually done with a QInputValidator, which forbids entering invalid values (before the data is changed at all).

    That's exactly what i'm looking for ! Keeping that in mind for once i did the writing correct implementation.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.