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. QLabel isnt transparent when rendered on item delegate (QStyledItemDelegate)
Qt 6.11 is out! See what's new in the release blog

QLabel isnt transparent when rendered on item delegate (QStyledItemDelegate)

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 1.7k 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.
  • U Offline
    U Offline
    umen242
    wrote on last edited by
    #1

    i have strange problem i have item delegate inherit from QStyledItemDelegate
    the background color is gradient color that looks like this :
    @void ItemDelegate::paintActiveOverlay( QPainter *painter, qreal x, qreal y, qreal w, qreal h ) const {

    QPalette palette;
    QColor highlightColor = palette.color(QPalette::Highlight);
    QColor backgroundColor = palette.color(QPalette::Base);
    const float animation = 0.25;
    const int gradientRange = 16;
    
    QColor color2 = QColor::fromHsv(
            highlightColor.hue(),
            (int) (backgroundColor.saturation() * (1.0f - animation) + highlightColor.saturation() * animation),
            (int) (backgroundColor.value() * (1.0f - animation) + highlightColor.value() * animation)
            );
    QColor color1 = QColor::fromHsv(
            color2.hue(),
            qMax(color2.saturation() - gradientRange, 0),
            qMin(color2.value() + gradientRange, 255)
            );
    QRect rect((int) x, (int) y, (int) w, (int) h);
    painter->save();
    painter->setPen(Qt::NoPen);
    QLinearGradient linearGradient(0, 0, 0, rect.height());
    linearGradient.setColorAt(0.0, color1);
    linearGradient.setColorAt(1.0, color2);
    painter->setBrush(linearGradient);
    painter->drawRect(rect);
    painter->restore();
    

    }

    @

    its called from the paint method
    also in the ItemDelegate constructor i have set QLable like this :

    @QRect rect(40, 30, 401, 31);
    Qt::TextInteractionFlags flags = Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse|Qt::TextBrowserInteraction|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse;
    Qt::TextFormat txtFormat = Qt::PlainText;

    pTextEdit_title = new QLabel();
    pTextEdit_title->setTextFormat(txtFormat);
    pTextEdit_title->setTextInteractionFlags(flags);
    pTextEdit_title->setGeometry(rect);@

    and in the paint method of the ItemDelegate i set the Qlable to render like this :
    @pTextEdit_title->setText(Title);
    QRect TextEditRect(option.rect.x()+THUMB_WIDTH+THUMB_WIDTH+PADDING, option.rect.y() ,
    pTextEdit_title->width(), pTextEdit_title->height());
    QPixmap pixmap(pTextEdit_title->size());
    pTextEdit_title->render(&pixmap);
    painter->drawPixmap(TextEditRect,pixmap);
    @

    it render the QLable file , but the problem is that it has gray background and dosnt act as transparent background , my question is how to set the QLable background to be transparent?

    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