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 keep rows together in QListView?

How to keep rows together in QListView?

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 1.2k 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.
  • T Offline
    T Offline
    tokafr
    wrote on last edited by
    #1

    Hello again.

    I have QListView and a delegate, delegate sets the height of row with sizeHint method.
    then I switch listView to IconMode and sizeHint returns different values, but then, when I switch it back to list mode the rows have right height but there is free space between each row.
    I don't want it I want them to be together what I should do?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Subst27
      wrote on last edited by
      #2

      try use QAbstractListModel::data and handle Qt::SizeHintRole

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on last edited by
        #3

        [quote author="Subst27" date="1421328209"]try use QAbstractListModel::data and handle Qt::SizeHintRole[/quote]

        I disagree. The model should not concern itself with how it is viewed.

        @tokafr: you mention that you are using different sizeHints for different view modes? Could you show your code?

        Perhaps it is a matter of using two different itemDelegates for the modes.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          Subst27
          wrote on last edited by
          #4

          [quote author="Andre" date="1421329134"]I disagree. The model should not concern itself with how it is viewed.
          [/quote]

          really?? why?

          such code in my program work perfect. Yes I'm not use SizeHint it this code, but what difference

          @QVariant TTtxModel::data(const QModelIndex &index, int role) const
          {
          QRegExp regxp1;
          regxp1.setMinimal(true);
          regxp1.setPattern(QString("<foreignphrase.>.</foreignphrase>").toHtmlEscaped());

          QRegExp regxp2;
          regxp2.setMinimal(true);
          regxp2.setPattern(QString("<emphasis.>.</emphasis>").toHtmlEscaped());
          switch (role)
          {
          case Qt::BackgroundRole:
          {
          //QString text=m_data[index.row()][SourceUi].toString();

          if (m_data[index.row()][Status].toInt()==Corrected)
          return QColor::fromRgb(146, 208, 80);//0,128,255);

          if (m_data[index.row()][Status].toInt()==Ignored)
          return QColor::fromRgb(166, 166, 166);//0,128,255);

          if (m_data[index.row()][Error].toInt()==GlossaryError)
          return QColor::fromRgb(255, 146, 146);

          if (m_data[index.row()][Error].toInt()==ConsistencyError)
          return QColor::fromRgb(197, 217, 241);

          if (m_data[index.row()][Error].toInt()==TagError)
          return QColor::fromRgb(255, 255, 80);

          //if (m_data[index.row()][Status].toInt()==Visited)
          // return QColor::fromRgb(255,255,128);//0,128,255);

          break;
          }
          case Qt::TextAlignmentRole:
          {
          switch (index.column())
          {
          case Segment:
          case Line:
          case Section:
          case Item:
          {
          return QVariant(Qt::AlignVCenter | Qt::AlignRight);
          break;
          }
          case Arch:
          case SourceAttr:
          case TargetAttr:
          case SourceUi:
          case TargetUi:
          case Glossary:
          case Error:
          case Status:
          {
          return QVariant(Qt::AlignVCenter | Qt::AlignLeft);
          break;
          }
          }
          break;
          }
          case Qt::DisplayRole:
          {
          if (index.column()==Error)
          {
          switch (m_data[index.row()][index.column()].toInt())
          {
          case NoError:
          {
          return QString();
          break;
          }
          case GlossaryError:
          {
          return tr("Glossary Error");
          break;
          }
          case ConsistencyError:
          {
          return tr("Consistency Error");
          break;
          }
          case TagError:
          {
          return tr("Tag Error");
          break;
          }
          default:
          {
          return tr("Unknown Error");
          break;
          }
          }
          }

          if (index.column()==Status)
          {
          switch (m_data[index.row()][index.column()].toInt())
          {
          case NoError:
          {
          return QString();
          break;
          }
          case Corrected:
          {
          return tr("Corrected");
          break;
          }
          case Visited:
          {
          return tr("Visited");
          break;
          }
          case Ignored:
          {
          return tr("Ignored");
          break;
          }
          default:
          {
          return tr("Unknown");
          break;
          }
          }
          }
          return m_data[index.row()][index.column()];
          break;
          }

          case Qt::UserRole:
          {
          return m_data[index.row()][index.column()];
          break;
          }
          }
          return QVariant();
          }@

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

            [quote author="Subst27" date="1421329491"][quote author="Andre" date="1421329134"]I disagree. The model should not concern itself with how it is viewed.
            [/quote]

            really?? why?
            [/quote]

            Separation of concerns. The model is there to provide the data in a structured way, not to determine how it is displayed. I consider those roles a design mistake in the item view framework (and not the only one either).

            What happens for instance if you want to show your model in two different views at the same time, for instance like a file explorer does showing a tree with just the directories and a list or table view with the details of the selected directory? Now, put the file view in icon mode. Those are two views on the same data model (the file system). If you dictate size hints from the model, that would impact both displays... Not what you want.

            1 Reply Last reply
            0
            • T Offline
              T Offline
              tokafr
              wrote on last edited by
              #6

              done, just reset() :) :) :)

              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