Results 1 to 2 of 2

Thread: how to mask my x::widget to the background of a shape

  1. #1
    Join Date
    Feb 2012
    Location
    Armenia/Yerevan
    Posts
    400
    Thanks
    15
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default how to mask my x::widget to the background of a shape

    hi there,

    I gotta draw a rounded rectangle n fit MultiSlider widget inside of it. I was told I'd be able to present it with setmas().
    here's the code, please add the required code for me.

    Qt Code:
    1. void QtMultiSlider::paintEvent(QPaintEvent * event)
    2. {
    3. Q_UNUSED(event)
    4.  
    5. if (!isVisible())
    6. return;
    7.  
    8. QPainter painter;
    9. painter.begin(this);
    10.  
    11. painter.setPen(Qt::blue);
    12. painter.setBrush(Qt::SolidPattern);
    13. QRect rect(50, 50, 240, 100);
    14. painter.setRenderHint(QPainter::Antialiasing, true);
    15. painter.drawRoundedRect(rect, 25, 25, Qt::RelativeSize);
    16.  
    17. int spacing = 30;
    18. int labelHeight = 0;
    19.  
    20. int valueBarWidth = 300;
    21.  
    22. // Calculating the maximum string size
    23.  
    24. int valueBarX = spacing;
    25. int valueBarBottomY = 0;
    26.  
    27. QSizeF originalSize = m_rendererValueBarTop->defaultSize();
    28. QSizeF targetSize = originalSize;
    29. targetSize.scale(QSizeF(valueBarWidth, originalSize.height()), Qt::KeepAspectRatio);
    30. qreal scaleRatio = targetSize.width() /
    31. originalSize.width();
    32.  
    33. QSize valueBarBottomSize = m_rendererValueBarBottom->defaultSize() * scaleRatio;
    34.  
    35. valueBarBottomY = height() - labelHeight - 20
    36. - valueBarBottomSize.height();
    37.  
    38. m_valueBarRightRect = QRect(QPoint(valueBarX, 20),
    39. QSize(valueBarWidth, valueBarBottomY));
    40.  
    41. m_rendererValueBar->render(&painter, m_valueBarRightRect);
    42.  
    43. int filledPixels = ((double)value()) / maximum() * m_valueBarRightRect.height();
    44. QRect filledRect = m_valueBarRightRect;
    45. filledRect.setTop(filledRect.bottom() - filledPixels);
    46. m_rendererValueBarFilled->render(&painter, filledRect);
    47.  
    48.  
    49. painter.end();
    50.  
    51. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Dec 2010
    Location
    Russia
    Posts
    83
    Thanks
    1
    Thanked 12 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to mask my x::widget to the background of a shape

    Heh , asking someone to do the job for you doesn't sound right (at least on this forum). As you were told you can use greyscale images to mask desired areas.
    Look at the void QWidget::setMask ( const QBitmap & bitmap ) description for full info.

Similar Threads

  1. Replies: 0
    Last Post: 18th January 2011, 16:59
  2. How to set a widget as background?
    By Patrick Sorcery in forum Qt Programming
    Replies: 7
    Last Post: 25th October 2010, 11:41
  3. Widget as desktop background
    By abeinoe in forum The GraphicsView Framework
    Replies: 0
    Last Post: 30th January 2009, 07:15
  4. Qwt overrides Widget background
    By garfield in forum Qwt
    Replies: 1
    Last Post: 18th December 2007, 08:16
  5. Custom Shape Widget (resize)
    By PiXeL16 in forum Qt Programming
    Replies: 7
    Last Post: 12th February 2007, 07:00

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.