2017-04-22 80 views
0

我已經嘗試了很多在stackoverflow上提供的解決方案,使它透明。 我想讓QRubberBand透明,並且我也面臨着由於mplayer而產生的綠色問題。在QLabel中的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

http://imgur.com/tUYSOdk –

+0

http://imgur.com/2gnndL3 –

+0

我也想讓這個QRubberBand應該對QLabel在MPlayer是嵌入式 –

回答

0

首先,關於 「QRubberBand應該只在QLabel工作」。您需要使QRubberBand的父母QLabel達到此目的。

其次,關於透明度,我認爲你的意思是從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)); 
    } 
}; 

以上仍然留視覺假象的小部件,但。

+0

你可以幫助如何刪除才起作用綠色?? –

+0

我真的不能上果嶺邊緣不知道正是這小部件的影響發表評論(是相同的部件,其窗口ID被傳遞到mplayer的?)。一個建議可能是嘗試一個不同的'-vo'選項。在命令行執行「mplayer -vo help」並嘗試一些可用的選項。 –

+0

我很欣賞你的答案ATLEAST你盡力幫助我(是的,它是受到了影響,其ID傳遞給mplayer的相同部件),但由於你的建議,我認爲我應該帶參數,我已經通過了,然後我刪除縮放參數玩最後我擺脫了那種綠色。 –