Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. What is the best tool to use

What is the best tool to use

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
7 Posts 2 Posters 945 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.
  • V Offline
    V Offline
    Vlad02
    wrote on last edited by
    #1

    Hi everybody! I need create layout of processor memory. It looks like this:
    104b2317-d546-4de0-be7a-f73389471a94-image.png
    I should be able to edit each cell, to block some cells so that nothing can be written there, read value from cells and move on they. I had idea create many QLineEdit, but 288 elements so much and I don't know how comfortably address to specific cell. So what tools can help to do work more easily? Thanks!

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      Hi
      Either use QTableWidget or QTableView
      https://doc.qt.io/qt-6/qtablewidget.html

      They provide almost anything you need and will be much easier to handle than a ton of LineEdits.

      To get that exact look, you can use a Delegate to handle the drawing so it can be grey when zero and while with values and so on.

      https://doc.qt.io/qt-6/qitemdelegate.html#details
      https://doc.qt.io/qt-6/qstyleditemdelegate.html#details

      V 1 Reply Last reply
      1
      • mrjjM mrjj

        Hi
        Either use QTableWidget or QTableView
        https://doc.qt.io/qt-6/qtablewidget.html

        They provide almost anything you need and will be much easier to handle than a ton of LineEdits.

        To get that exact look, you can use a Delegate to handle the drawing so it can be grey when zero and while with values and so on.

        https://doc.qt.io/qt-6/qitemdelegate.html#details
        https://doc.qt.io/qt-6/qstyleditemdelegate.html#details

        V Offline
        V Offline
        Vlad02
        wrote on last edited by
        #3

        @mrjj Oh, thank you. I will definitely check it out and try!

        mrjjM 1 Reply Last reply
        0
        • V Vlad02

          @mrjj Oh, thank you. I will definitely check it out and try!

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #4

          @Vlad02
          Hi
          just as a note.
          You might be able to use
          https://doc.qt.io/qt-6/qtablewidgetitem.html#setForeground
          for the coloring instead of a delegate but it can become a bit clumsy as you then need to loop over all cells
          if data changes to reset or change colors.

          update:

          The delegate might seem a bit much the first time so here is a quick example to build on.

          alt text

          class TextColorDelegate : public QStyledItemDelegate
          {
              Q_OBJECT
              Q_DISABLE_COPY(TextColorDelegate)
          public:
              explicit TextColorDelegate(QObject *parent = Q_NULLPTR)
                  : QStyledItemDelegate(parent)
              {}
              void paint(QPainter *painter, const QStyleOptionViewItem &option,
                         const QModelIndex &index) const Q_DECL_OVERRIDE
              {
                  const QStyle *style = option.widget ? option.widget->style() : QApplication::style();
                  QVariant dat = index.data(); // the items text
                  if (dat.toInt() == 0)
                      painter->setPen(Qt::gray);
                  else
                      painter->setPen(Qt::white);
                  // first col should be green
                  if (index.column() == 0 )
                      painter->setPen(Qt::green);
                  // fill background
                  painter->fillRect(option.rect, Qt::black);
                  //draw text
                  style->drawItemText(painter, option.rect, Qt::AlignCenter, option.palette,
                                      option.state & QStyle::State_Enabled, dat.toString() );
              }
          };
          
          

          ..
          ui->tableWidget->setItemDelegate(new TextColorDelegate);

          V 1 Reply Last reply
          2
          • mrjjM mrjj

            @Vlad02
            Hi
            just as a note.
            You might be able to use
            https://doc.qt.io/qt-6/qtablewidgetitem.html#setForeground
            for the coloring instead of a delegate but it can become a bit clumsy as you then need to loop over all cells
            if data changes to reset or change colors.

            update:

            The delegate might seem a bit much the first time so here is a quick example to build on.

            alt text

            class TextColorDelegate : public QStyledItemDelegate
            {
                Q_OBJECT
                Q_DISABLE_COPY(TextColorDelegate)
            public:
                explicit TextColorDelegate(QObject *parent = Q_NULLPTR)
                    : QStyledItemDelegate(parent)
                {}
                void paint(QPainter *painter, const QStyleOptionViewItem &option,
                           const QModelIndex &index) const Q_DECL_OVERRIDE
                {
                    const QStyle *style = option.widget ? option.widget->style() : QApplication::style();
                    QVariant dat = index.data(); // the items text
                    if (dat.toInt() == 0)
                        painter->setPen(Qt::gray);
                    else
                        painter->setPen(Qt::white);
                    // first col should be green
                    if (index.column() == 0 )
                        painter->setPen(Qt::green);
                    // fill background
                    painter->fillRect(option.rect, Qt::black);
                    //draw text
                    style->drawItemText(painter, option.rect, Qt::AlignCenter, option.palette,
                                        option.state & QStyle::State_Enabled, dat.toString() );
                }
            };
            
            

            ..
            ui->tableWidget->setItemDelegate(new TextColorDelegate);

            V Offline
            V Offline
            Vlad02
            wrote on last edited by
            #5

            @mrjj Okey, thank you so much!

            1 Reply Last reply
            0
            • V Offline
              V Offline
              Vlad02
              wrote on last edited by
              #6
              This post is deleted!
              1 Reply Last reply
              0
              • V Offline
                V Offline
                Vlad02
                wrote on last edited by
                #7

                @mrjj Hi! Sorry for worry! I don't understand, how I can change style of certain cell in different cases. For example, if I click on cell, it must change background-color. If I click on button, it must change background after a few clicks. Already read documentation, search in Internet at least some ways but without examples can't understand, how this do. And how I can do that cells could change after click on button not double-clicking on them?

                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