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. Incorrect drawn images and checkboxes in table
Qt 6.11 is out! See what's new in the release blog

Incorrect drawn images and checkboxes in table

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 5.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.
  • S Offline
    S Offline
    saifas
    wrote on last edited by
    #1

    We have following problem. We have custom drawn table with images and checkboxes. They are located in adjacent columns. When we compile and run on Linux, everything works fine, but on Windows when hovering mouse over checkboxes, images will be erased by background. It seems like when checkbox is redrawn, it takes some of the image's area. Can you explain the difference in behavior, and how to make everything to be displayed correctly on both OSes?

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

      Well, that would be hard, considdering that you're not showing us the code.
      For starters, it is unclear what you mean by a a "custom drawn table": did you make your own table, or do you use QTableView with a custom QItemDelegate implementation?

      I think you'll have more luck getting a useful answer if you show us the code you use for the drawing.

      1 Reply Last reply
      0
      • G Offline
        G Offline
        giesbert
        wrote on last edited by
        #3

        Can you please provide some snapshots and code?
        In general, it should work via different platforms.

        But if it's custom drawn, what do you draw by yourself?

        Nokia Certified Qt Specialist.
        Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

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

          Here are sources which I think are related to problem. This is custom delegate that paints everything in table except for checkboxes. Checkboxes are created with standard qt means (CheckStateRole in model).

          !https://docs.google.com/leaf?id=0BxBq4gR3KdyjNzU0ZTdmMzQtNDgzMS00MGUwLTgxZGEtN2M3MDg0NTM4MmY1&hl=en()!
          @void
          DemandJournalistStatusDelegate::paint(QPainter *aPainter,
          const QStyleOptionViewItem &aOption,
          const QModelIndex &aIndex) const
          {
          int cellHeight = 20;
          int rectY = aOption.rect.y();
          int rectWidth = aOption.rect.width();
          int tempX = 3;

          QRect rect;
          QRect source;
          ...
          //draw Avatar
          source.setRect(0, -3, 20, 20);
          rect.setRect(tempX, rectY, 20, cellHeight);
          aPainter->drawImage(rect, ImagesCache::instance()->get(Nick), source);
          tempX += 20;

          //draw Name
          rect.setRect(tempX, rectY, mMapWidth[0]-23, cellHeight);
          aPainter->drawText(rect, Qt::AlignVCenter | Qt::TextWordWrap, MetricsName);

          tempX = mMapWidth[0];
          ...
          }@

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

            I assume that you let Qt draw the check boxes by calling the base implementation or something of paint() or something like that? I think that is the key part of the code, and it is a pitty it has been omitted here.

            If you do that, how about changeing the order in which you draw your stuff. If you first draw the checkbox, you can start drawing your own content at whatever place you want. That will ensure the checkbox does not overdraw your own content. Notice that you can get the dimentions of the check box from the style, no need to hard code that.

            1 Reply Last reply
            0
            • S Offline
              S Offline
              saifas
              wrote on last edited by
              #6

              I don't call base paint to draw checkbox. I simply provide Qt::CheckStateRole in model's data() function, and don't use anything else. Thanks for the advice though. Maybe the problem is indeed with hardcoded checkbox size. Can you tell, how I can obtain its dimensions from style?

              @QVariant
              ChannelsListTableModel::data ( const QModelIndex & aIndex,
              int role ) const
              {
              if(role == Qt::CheckStateRole)
              {
              if(aIndex.column()==1)
              if(mDataChek.value(aIndex.row())) return Qt::Checked;
              if(!mDataChek.value(aIndex.row())) return Qt::Unchecked;
              }
              ...
              }@

              @bool
              ChannelsListTableModel::setData (const QModelIndex& aIndex,
              const QVariant & aValue,
              int aRole)
              {
              if(mCheckEnable[aIndex.row()])
              {
              if( aRole == Qt::CheckStateRole && aIndex.column()==1)
              {
              if(mDataChek.value(aIndex.row())==true)
              {
              mDataChek.insert(aIndex.row(),false);
              return Qt::Unchecked;
              }
              else
              {
              mDataChek.insert(aIndex.row(),true);
              return Qt::Checked;
              }
              }
              }
              return Qt::Unchecked;
              }@

              1 Reply Last reply
              0
              • S Offline
                S Offline
                saifas
                wrote on last edited by
                #7

                ohh! thanks for advice, I tried to obtain dimensions from style and it worked!!!
                In case some needs it here is what I did:
                @tempX += QApplication::style()->subElementRect(QStyle::SE_CheckBoxClickRect,&aOption).x();@

                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