2011-10-30 5 views
4

슬라이더 배경을 페인트하고 싶습니다. 나는 이것을 시도했지만 색상은 전체 슬라이더를 덮는다. 당신이 할 수 있도록, 다음은 위젯의 배경을 설정합니다백그라운드에서 Qt drawRect

theSlider->setStyleSheet("QSlider { background-color: green; }"); 

: 이것은 당신이 스타일 시트를 설정할 수있는 위젯의 배경을 설정하려면 QSlider

void paintEvent(QPaintEvent *e) { 
    QPainter painter(this); 
    painter.begin(this); 
    painter.setBrush(/*not important*/); 

    // This covers up the control. How do I make it so the color is in 
    // the background and the control is still visible? 
    painter.drawRect(rect()); 

    painter.end(); 
} 
+1

위젯의 배경을 페인트하고 싶습니까? 제발 좀 더 구체적으로 말하십시오. –

답변

9

의 상속 클래스에 더 :

void paintEvent(QPaintEvent *event) { 
    QPainter painter; 
    painter.begin(this); 
    painter.fillRect(rect(), /* brush, brush style or color */); 
    painter.end(); 

    // This is very important if you don't want to handle _every_ 
    // detail about painting this particular widget. Without this 
    // the control would just be red, if that was the brush used, 
    // for instance. 
    QSlider::paintEvent(event);  
} 

그리고 btw. 샘플 다음 두 줄의 코드는 경고를 얻을 것입니다 :

QPainter painter(this); 
painter.begin(this); 

을 즉 GCC 사용하여이 하나 :: 시작

QPainter를을 : 페인트 장치는 (A)에서 한 화가가 그린 수 있습니다 시각. 난 당신이 중 하나가 QPainter painter(this) 또는 painter.begin(this)을 수행하는 것이 나의 예에서와

그래서, 확인하십시오.