QLabel中的QRubberBand和MPlayer [英] QRubberBand and MPlayer in QLabel
问题描述
我已经尝试过stackoverflow提供的许多解决方案以使其透明. 我想使QRubberBand透明,并且由于mplayer而使绿色也面临问题.
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);
}
推荐答案
首先,关于"QRubberBand仅应在该QLabel上工作".您需要将QLabel
作为QRubberBand
的父级.
Firstly, regarding "QRubberBand should work only on that QLabel". You need to make the QLabel
the parent of the QRubberBand
to achieve that.
第二,关于透明度,我想您是说mplayer的输出应该通过QRubberBand
绘制的矩形可见?我不确定您是否能够做到这一点.这样做将需要橡皮筋绘画逻辑充当合成器,但要做到这一点,它需要知道源图像和目标图像(mplayer).由于mplayer直接在基础本机窗口上绘制,因此Qt
知道当前目标图像,因此无法将源图像与其合并.我认为您最好的选择是查找/生成使QRubberBand
仅绘制矩形轮廓的样式-不知道是否可能.您可以将其子类化,然后使用类似...的绘画来进行自己的绘画.
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.
这篇关于QLabel中的QRubberBand和MPlayer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!