我已经尝试过在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);
}
答案 0 :(得分:0)
首先,关于&#34; QRubberBand应该仅适用于那个QLabel&#34;。您需要将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));
}
};
上面的内容仍然会在窗口小部件上留下视觉瑕疵。