Qt

2009-08-24 4 views
2

を使って、フラットイメージを3Dハイライト(iPhone)で素敵な丸いイメージに変換するiPhoneで、アプリアイコンの45x45 フラットイメージを与えると、SDKは自動的にラウンドしてハイライトします。それは新しい3D効果です。 Qt4 APIを使用してこれをエミュレートする方法のサンプルコードまたは推奨事項はありますか?おかげで、--DDQt

答えて

6

を参照してください:丸いを矩形、微妙な勾配に3Dの外観、そして輝きを与えます。しかし、もしあなたがお互いの上に2つの画像を重ね合わせることができれば、それはおそらく可能性があります。 1つは透過性のある丸みを帯びた3Dマスク画像で、その後45X45の画像をその背後に置くだけです。しかし、この時点でどのように拡張可能なqstylesheetがあるのか​​分かりません。

ただし、QPainterを使用することもできます。それは間違いなくあなたが必要とするすべてを行うことができます。基本的には、ウィジェット、QPushButton、QLabel ...のpaintEvent()をオーバーライドするだけです。ソースイメージを使用して自分で描画します。ここでは、QPushButtonをカスタムペイントして、Windows Aeroの外観を与えるためのWikiエントリへのリンクを示します。http://wiki.qtcentre.org/index.php?title=AeroButton

ここでは、クラスのpaintEvent()あなたに出発点を与える。アシスタントを使用すると、アシスタントを使用して簡単に操作できます。

void AeroButton::paintEvent(QPaintEvent * pe) 
{ 
    Q_UNUSED(pe); 

    QPainter painter(this); 
    painter.setRenderHint(QPainter::Antialiasing); 

    //test for state changes 
    QColor button_color; 
    if(this->isEnabled()) 
    { 
     m_hovered ? button_color = m_highlight : button_color = m_color; 

     if(m_pressed) 
     { 
       button_color = m_highlight.darker(250); 
     } 
    } 
    else 
    { 
     button_color = QColor(50, 50, 50); 
    } 

    QRect button_rect = this->geometry(); 

    //outline 
    painter.setPen(QPen(QBrush(Qt::black), 2.0)); 
    QPainterPath outline; 
    outline.addRoundedRect(0, 0, button_rect.width(), button_rect.height(), m_roundness, m_roundness); 
    painter.setOpacity(m_opacity); 
    painter.drawPath(outline); 

    //gradient 
    QLinearGradient gradient(0, 0, 0, button_rect.height()); 
    gradient.setSpread(QGradient::ReflectSpread); 
    gradient.setColorAt(0.0, button_color); 
    gradient.setColorAt(0.4, m_shadow); 
    gradient.setColorAt(0.6, m_shadow); 
    gradient.setColorAt(1.0, button_color); 

    QBrush brush(gradient); 
    painter.setBrush(brush); 
    painter.setPen(QPen(QBrush(button_color), 2.0)); 

    //main button 
    QPainterPath painter_path; 
    painter_path.addRoundedRect(1, 1, button_rect.width() - 2, button_rect.height() - 2, m_roundness, m_roundness); 
    painter.setClipPath(painter_path); 

    painter.setOpacity(m_opacity); 
    painter.drawRoundedRect(1, 1, button_rect.width() - 2, button_rect.height() - 2, m_roundness, m_roundness); 

    //glass highlight 
    painter.setBrush(QBrush(Qt::white)); 
    painter.setPen(QPen(QBrush(Qt::white), 0.01)); 
    painter.setOpacity(0.30); 
    painter.drawRect(1, 1, button_rect.width() - 2, (button_rect.height()/2) - 2); 

    //text 
    QString text = this->text(); 
    if(!text.isNull()) 
    { 
     QFont font = this->font(); 
     painter.setFont(font); 
     painter.setPen(Qt::white); 
     painter.setOpacity(1.0); 
     painter.drawText(0, 0, button_rect.width(), button_rect.height(), Qt::AlignCenter, text); 
    } 

     //icon 
     QIcon icon = this->icon(); 
     if(!icon.isNull()) 
     { 
     QSize icon_size = this->iconSize(); 
     QRect icon_position = this->calculateIconPosition(button_rect, icon_size); 
     painter.setOpacity(1.0); 
     painter.drawPixmap(icon_position, QPixmap(icon.pixmap(icon_size))); 
     } 
} 
0

(私は実際にそれを試していないので、これは提案です)

スタイルシートすなわち:

QPushButton { 
    background: qlineargradient(/*specify pattern here, with colors with alpha channel (0, 0, 0, 150) for example */); 
    image: url(:/reference/to/img/in_q_resourceFile); 
} 

私はそれはあなたを与えるだろうと、これは、最も簡単な解決策だと思いますクリック可能なqpushbutton。

私はあなたがiphoneアプリのアイコンの完全な効果をしたい場合は、スタイルシートは、あなたが求めているすべてを行うことができわからない...スタイルシートを作成する方法についてのアシスタントに