0

I have already tried many solution that are provided on stackoverflow to make it transparent. I want to make QRubberBand transparent and i am also facing problem regarding that green color which is due to mplayer.

   #include "physician.h"
   #include "ui_physician.h"

    Physician::Physician(QWidget *parent) :
         QMainWindow(parent),
         ui(new Ui::Physician)
    {
         ui->setupUi(this);
         ui->sendROIButton->setStyleSheet(
                    "background-color: #d9d9d9;"
                    "border-radius: 10px;"
                    "color: Black; "
                    "font-size: 15px;"
         );
     }

     Physician::~Physician()
     {
         delete ui;
     }

     void Physician::mouseMoveEvent(QMouseEvent *e)
     {
         rubberBand->hide();
         bottomRight = e->pos();
         QRect rect = QRect(topLeft, bottomRight).normalized();
         rubberBand->setGeometry(rect);//Area Bounding
         QToolTip::showText(e->globalPos(), QString("%1,%2")
        .arg(rubberBand->size().width())
        .arg(rubberBand->size().height()), this);
      }
      void Physician::mousePressEvent(QMouseEvent *e)
      {
        wWidth=ui->videoShowLabel->width();
        wHeight = ui->videoShowLabel->height();
        rubberBand->setGeometry(QRect(0, 0, 0, 0).normalized());
        rubberBand->hide();
        topLeft = e->pos();
       }
       void Physician::mouseReleaseEvent(QMouseEvent *e){
        rubberBand->show();
       }

       void Physician::on_manualROIRadioButton_clicked()
       {
         rubberBand = new QRubberBand(QRubberBand::Rectangle, this);
       }

       void Physician::on_autoROIRadioButton_clicked()
       {
         QString winNuber= QString::number((int)(ui->videoShowLabel->winId()));
         QStringList argsList ;
         argsList << "-slave" << "-quiet" << "-wid" << winNuber << "zoom" << "-
         vo" << "gl" << "C:/../../../Physician21/PhotoshopQML.mkv";
         mplayer_proc = new QProcess;
         mplayer_proc-
         >start("C:/../../../PhysicianTest/mplayer/mplayer.exe",argsList);
        }

1 Answers1

0

Firstly, regarding "QRubberBand should work only on that QLabel". You need to make the QLabel the parent of the QRubberBand to achieve that.

Secondly, regarding transparency I assume you mean that the output from mplayer should be visible through the rectangle painted by the QRubberBand? I'm not sure you will be able to do that. Doing so would required the rubber band painting logic to act as a compositor but in order to do that it needs to know both the source and destination(mplayer) images. Since mplayer draws directly on the underlying native window Qt has know knowledge of the current destination image and so can not merge the source image with it. I think your best bet would be to find/generate a style that causes QRubberBand to draw the rectangle outline only -- not sure if that's possible. You could subclass it and do your own painting with something like...

class rubber_band: public QRubberBand {
  using super = QRubberBand;
public:
  template<typename... Types>
  explicit rubber_band (const Types &... args)
    : super(args...)
    {}
protected:
  virtual void paintEvent (QPaintEvent *event) override
    {
      QPainter painter(this);
      painter.setPen(Qt::red);
      painter.setBrush(Qt::NoBrush);
      painter.drawRect(rect().adjusted(0, 0, -1, -1));
    }
};

The above could still leave visual artifacts on the widget though.

G.M.
  • 12,232
  • 2
  • 15
  • 18
  • can you help how to remove that green color?? – Muhammad Athar Jan Apr 26 '17 at 21:40
  • I can't really comment on the green edges without knowing precisely which widget is affected (is it the same widget whose window id is passed to mplayer?). One suggestion might be to try a different `-vo` option. Do "mplayer -vo help" at a command line and try a few of the available options. – G.M. Apr 27 '17 at 08:56
  • i appreciate your answer atleast you try to help me(yes it was the same widget that was affected whose id was passed to mplayer) but due to your suggestion i think that i should play with arguments that i have passed then i removed zoom argument and finally i get rid of that green color. – Muhammad Athar Jan Apr 27 '17 at 19:19