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. I am not able to see any image with following code
Qt 6.11 is out! See what's new in the release blog

I am not able to see any image with following code

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 1.4k Views 2 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.
  • Q Offline
    Q Offline
    Qt Enthusiast
    wrote on last edited by
    #1

    Hi All
    I have following code ,

    1. class myModel: public QAbstractItemModel {
      }

    2 ) QtreeView is using this model

    QVariant myModel::data() {
    case Qt::DecorationRole:
    if (index.column() == 0) {
    QPixmap pixmap(10,10);
    /* icon for transparent color*/
    pixmap.fill(QColor(0,0,0,0));
    QIcon icon(pixmap);
    return icon;
    }
    }

    If my QtreeView has white background , I cannot see anything . Could you let me know why I cannot see anything ., I have to have transparent color image box on white background .What to do ?

    raven-worxR 2 Replies Last reply
    0
    • Q Qt Enthusiast

      Hi All
      I have following code ,

      1. class myModel: public QAbstractItemModel {
        }

      2 ) QtreeView is using this model

      QVariant myModel::data() {
      case Qt::DecorationRole:
      if (index.column() == 0) {
      QPixmap pixmap(10,10);
      /* icon for transparent color*/
      pixmap.fill(QColor(0,0,0,0));
      QIcon icon(pixmap);
      return icon;
      }
      }

      If my QtreeView has white background , I cannot see anything . Could you let me know why I cannot see anything ., I have to have transparent color image box on white background .What to do ?

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @Qt-Enthusiast said in I am not able to see any image with following code:

      If my QtreeView has white background , I cannot see anything

      what does that mean? What are you expecting?
      You fill it transparent on purpose :)

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        Qt Enthusiast
        wrote on last edited by
        #3

        I wanted to see some box with a boundary and white background like a transparent box

        raven-worxR 1 Reply Last reply
        0
        • Q Qt Enthusiast

          I wanted to see some box with a boundary and white background like a transparent box

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          @Qt-Enthusiast
          then you need to draw a border inside the transparent pixmap?

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          1
          • Q Offline
            Q Offline
            Qt Enthusiast
            wrote on last edited by
            #5

            can u please code ?

            1 Reply Last reply
            0
            • Q Qt Enthusiast

              Hi All
              I have following code ,

              1. class myModel: public QAbstractItemModel {
                }

              2 ) QtreeView is using this model

              QVariant myModel::data() {
              case Qt::DecorationRole:
              if (index.column() == 0) {
              QPixmap pixmap(10,10);
              /* icon for transparent color*/
              pixmap.fill(QColor(0,0,0,0));
              QIcon icon(pixmap);
              return icon;
              }
              }

              If my QtreeView has white background , I cannot see anything . Could you let me know why I cannot see anything ., I have to have transparent color image box on white background .What to do ?

              raven-worxR Offline
              raven-worxR Offline
              raven-worx
              Moderators
              wrote on last edited by raven-worx
              #6

              @Qt-Enthusiast

              const int QSize iconSize(10,10);
              
              QPixmap pixmap(iconSize);
              pixmap.fill(Qt::transparent);
              
              QPen pen(Qt::red, 1.0);
              
              QPainter p(&pixmap);
              p.setBrush( Qt::NoBrush );
              p.setPen( pen );
              const int correctionTopLeft = qFloor( pen.width()/2.0 );
              const int correctionBottomRight = -qCeil( pen.width()/2.0 );
              p.drawRect( QRect(QPoint(0,0),iconSize).adjusted(correctionTopLeft,correctionTopLeft,correctionBottomRight,correctionBottomRight) );
              p.end();
              ...
              

              But i suggest instead of doing the painting every time the decoration role is requested you should use a PNG file instead or at least create the Ppxmap only once and cache/re-use it when needed.

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              1 Reply Last reply
              3

              • Login

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