Results 1 to 2 of 2

Thread: Custom QRubberBand with transparent background

  1. #1
    Join Date
    Jun 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Custom QRubberBand with transparent background

    Hi,

    as already discussed here and here it should be possible to paint modify the appearance of the QRubberBand by making a subclass and overwriting the paintEvent. The rubberband should be displayed on QGraphicsView to select some items on a QGraphicsScene. I'm able to modify the frame color but the background of the rubber band rect remains completely transparent (white). Here is my implementation of the QRubberBand subclass

    Qt Code:
    1. #include "SelectionFrame.h"
    2. #include <QPaintEvent>
    3. #include <QPainter>
    4. #include <QDebug>
    5.  
    6. SelectionFrame::SelectionFrame(Shape shape, QWidget *parent) :
    7. QRubberBand(shape, parent)
    8. {
    9. _border_color = QColor(0, 83, 235);
    10. _background_color = QColor(51, 122, 255);
    11. }
    12.  
    13. SelectionFrame::~SelectionFrame()
    14. {
    15. }
    16.  
    17. void SelectionFrame::paintEvent(QPaintEvent *event)
    18. {
    19. Q_UNUSED(event);
    20.  
    21. QPainter painter;
    22. QPen pen = QPen(_border_color);
    23. pen.setWidth(5);
    24. pen.setStyle(Qt::DashLine);
    25.  
    26. QBrush brush = QBrush(_background_color);
    27.  
    28. painter.begin(this);
    29. painter.setPen(pen);
    30. painter.setOpacity(0.5);
    31. painter.setBrush(brush);
    32. painter.drawRect(event->rect());
    33. painter.end();
    34. }
    To copy to clipboard, switch view to plain text mode 

    As the painter's pen has been set to dashed, I think I can see, that there is an additional border painted on top of the dashed line with the correctly set transparency. The background is however not painter. Does anyone have a suggestion how this can be done right?

  2. #2
    Join Date
    Jun 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Custom QRubberBand with transparent background

    I thin I remained a little bit unclear about what I'm trying to achieve. The rubber bands background (the content of the selection rectangle) should be semi-transparent and have a special color. In my understanding the rubber bands default behavior, at least on my system, is to have a completely transparent content area with only the borders painted.

Similar Threads

  1. Replies: 2
    Last Post: 19th April 2010, 12:49
  2. transparent background
    By fruzzo in forum Qt Programming
    Replies: 13
    Last Post: 18th March 2008, 14:42
  3. Transparent background on QLabel on transparent QWidget
    By codeslicer in forum Qt Programming
    Replies: 1
    Last Post: 13th February 2008, 02:10
  4. Transparent background Style
    By Lele in forum Qt Programming
    Replies: 5
    Last Post: 17th July 2006, 12:02
  5. Why the background is not transparent?
    By SkripT in forum Qt Programming
    Replies: 4
    Last Post: 9th May 2006, 01:17

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.