【问题标题】:QRubberBand and MPlayer in QLabelQLabel 中的 QRubberBand 和 MPlayer
【发布时间】:2017-04-22 13:03:18
【问题描述】:

我已经尝试了许多在 stackoverflow 上提供的解决方案以使其透明。 我想让 QRubberBand 透明,我也面临着与 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);
        }

【问题讨论】:

标签: qt transparent qlabel mplayer


【解决方案1】:

首先,关于“QRubberBand 应该只在那个 QLabel 上工作”。您需要将 QLabel 设为 QRubberBand 的父级以实现此目的。

其次,关于透明度,我假设您的意思是 mplayer 的输出应该通过QRubberBand 绘制的矩形可见?我不确定你能否做到这一点。这样做需要橡皮筋绘画逻辑充当合成器,但为了做到这一点,它需要知道源图像和目标(mplayer)图像。由于 mplayer 直接在底层原生窗口上绘制,Qt 知道当前目标图像,因此无法将源图像与其合并。我认为您最好的选择是找到/生成一种样式,使QRubberBand 仅绘制矩形轮廓——不确定这是否可能。您可以将其子类化并使用类似...的东西进行自己的绘画

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));
    }
};

尽管如此,上述内容仍可能在小部件上留下视觉伪影。

【讨论】:

  • 你能帮忙去掉那个绿色吗??
  • 如果不确切知道哪个小部件受到影响,我无法真正评论绿色边缘(它的窗口 ID 是传递给 mplayer 的同一个小部件吗?)。一个建议可能是尝试不同的-vo 选项。在命令行中执行“mplayer -vo help”并尝试一些可用选项。
  • 我很感激你的回答,至少你试图帮助我(是的,它是同一个受影响的小部件,其 id 被传递给了 mplayer)但由于你的建议,我认为我应该使用我的论点已经过去了,然后我删除了缩放参数,最后我摆脱了那种绿色。
猜你喜欢
  • 1970-01-01
  • 2016-03-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-11-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多