Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to display multiline messages in QTableView ?

How to display multiline messages in QTableView ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 2 Posters 1.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    ikuris
    wrote on last edited by
    #3

    Trouble starts when the data I'm reading is more than 10,000 rows.
    Each line has the message and other information. (I have 7 columns in my model).
    The number of lines in my messages may vary depending on the data I read.
    It can be 10 lines or 30.
    Thanks for your reply.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #4

      In that case you should compromise on a certain size to show your messages. Otherwise the view is going to have to do lots of calculation in order to be able to show all the different texts which are from different size.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      I 1 Reply Last reply
      0
      • SGaistS SGaist

        In that case you should compromise on a certain size to show your messages. Otherwise the view is going to have to do lots of calculation in order to be able to show all the different texts which are from different size.

        I Offline
        I Offline
        ikuris
        wrote on last edited by
        #5

        @SGaist
        Need to restrict message size?
        If I make such a restriction, what should I do to make QTableView show multi-line messages.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #6

          I meant the cell size.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          I 1 Reply Last reply
          0
          • SGaistS SGaist

            I meant the cell size.

            I Offline
            I Offline
            ikuris
            wrote on last edited by
            #7

            @SGaist
            I am sorry but I dont't quite understand what you are asking for. Even though I am using basic model with 5 columns , all of my rows(100.000) have "hello", It gets stuck with QTableView::setSectionSize(QHeaderView::ResizeToContents). After I am adding some other rows, or scrolling down, It gets stuck too. I can't even make the GUI full screen.
            I am curious if there is a way for only computing rowHeight only once because with this problem, TableView is updating height for every update to model or some filtering operations.
            You are asking me to comprimise message certain size but even though I have "Hello" in every cell problem still exists.
            Thank you for your response.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #8

              Don't use ResizeToContent as it is recalculating everything for each cell.

              How is your model implemented ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              I 1 Reply Last reply
              0
              • SGaistS SGaist

                Don't use ResizeToContent as it is recalculating everything for each cell.

                How is your model implemented ?

                I Offline
                I Offline
                ikuris
                wrote on last edited by
                #9

                @SGaist
                I have a custom model that inherits QAbstractTAbleModel. Inside that model I have a container (std::vector), a function for updating my vector and another function for beginInsertRows() and endInsertRows(), and other virtual functions. (rowCount, columnCount, data)

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #10

                  A vector of vector of string ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  I 1 Reply Last reply
                  0
                  • I Offline
                    I Offline
                    ikuris
                    wrote on last edited by
                    #11

                    struct MyCustomStruct
                    {
                    QString data1;
                    QString data2;
                    QString data3;

                    };

                    // MY CUSTOM MODEL .CPP
                    #include "mycustommodel.h"

                    MyCustomModel::MyCustomModel(QObject *parent) : QAbstractTableModel(parent)
                    {

                    }

                    void MyCustomModel::parseCustomStruct(const QByteArray &data)
                    {
                    std::vector<MyCustomStruct> tempVec;
                    MyCustomStruct str;
                    auto size = data.split('\n').size();
                    for(;size!=0;--size){
                    str.data1 = "DATA1";
                    str.data2 = "DATA2";
                    str.data3 = "DATA3";
                    tempVec.push_back(str);
                    }
                    updateModel(tempVec);
                    }

                    void MyCustomModel::updateModel(const std::vector<MyCustomStruct> vec)
                    {
                    beginInsertRows(QModelIndex(), myData.size(), myData.size() + vec.size() -1);
                    myData.insert(myData.end(), vec.begin(), vec.end());
                    endInsertRows();

                    }

                    int MyCustomModel::rowCount(const QModelIndex &parent) const
                    {
                    Q_UNUSED(parent);
                    return myData.size();
                    }

                    int MyCustomModel::columnCount(const QModelIndex &parent) const
                    {
                    Q_UNUSED(parent);
                    return 3;
                    }

                    QVariant MyCustomModel::data(const QModelIndex &index, int role) const
                    {
                    if( !index.isValid() || role != Qt::DisplayRole )
                    {
                    return QVariant();
                    }
                    switch(index.column())
                    {
                    case 0:
                    return myData[index.row()].data1;
                    case 1:
                    return myData[index.row()].data2;
                    case 2:
                    return myData[index.row()].data3;

                    }
                    return QVariant();
                    }

                    QVariant MyCustomModel::headerData(int section, Qt::Orientation orientation, int role) const
                    {
                    if(role != Qt::DisplayRole )
                    {
                    return QVariant();
                    }
                    if(orientation == Qt::Horizontal)
                    {
                    switch(section)
                    {
                    case 0:
                    return QLatin1String("Hallo");
                    case 1:
                    return QLatin1String("Hallo");
                    case 2:
                    return QLatin1String("Hallo");
                    }
                    }
                    if(orientation == Qt::Vertical)
                    {
                    return section + 1;
                    }
                    return QVariant();
                    }

                    1 Reply Last reply
                    0
                    • SGaistS SGaist

                      A vector of vector of string ?

                      I Offline
                      I Offline
                      ikuris
                      wrote on last edited by
                      #12

                      @SGaist
                      Let me just post my model.

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved