Qt的event事件的相關問題
				
					![]() 
					
					
					
						發表于2019-05-10
						回復:0
						查看:4614  |  
					
				 
				
					我自定義了了一個自己的pushbutton類,
<pre class='brush: cpp'>class MyButton:public QPushButton
{
public:
    explicit MyButton(QWidget *parent = 0);
    bool event(QEvent *e);
};
MyButton::MyButton(QWidget *parent)
    :QPushButton(parent){
}
bool MyButton::event(QEvent *e){
    if(this->isEnabled() == true){
        if(e->type() == QEvent::MouseButtonPress){
            this->setStyleSheet("background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:0, y2:1.000, stop:0 #07a8e1, stop:1 #036098);");
        }
        if(e->type() == QEvent::HoverEnter){
            this->setStyleSheet("background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:0, y2:1.000, stop:0 #07a8e1, stop:1 #05629a);");
        }
        if(e->type() == QEvent::HoverLeave){
           this->setStyleSheet("background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:0, y2:1.000, stop:0 rgba(6, 180, 242, 255), stop:1 rgba(2, 127, 202, 255));");
        }
   }
    return true;
}</pre>
當我在程序中使用這個自定義的控件的時候,程序運行起來的時候空間居然看不到了。但是如果我把最后一行return true改為:return QPushButton::event(event),控件就可以看到并且正常運行,這是為什么?					
					
											
					
									 
			
登錄 慧都網發表評論