0

さまざまなクリック可能なアイコンと、それらのアイコンの下にQLabelを使用してテキストを配置できるウィジェットが必要です。

これは画像です:ここに画像の説明を入力してください

これには微調整とサブクラス化が必要になることを私は知っています。これを行うための最良の適切な方法は何でしょうか?これらのクリック可能なアイコンがQGraphicsViewに表示されることを私は知っています。

4

1 に答える 1

1

QGraphicsViewを使用することをお勧めします。

クリック可能なピックスマップのサンプルは次のとおりです。

ClickablePixmap::ClickablePixmap( QGraphicsItem* itemParent )
    : QObject(0)
    , QGraphicsPixmapItem(itemParent)
    , m_pressed(false)
{
    setFlags(QGraphicsItem::ItemIsFocusable |
             QGraphicsItem::ItemIsSelectable |
             QGraphicsItem::ItemSendsGeometryChanges |
             QGraphicsItem::ItemIgnoresParentOpacity
             );
    setAcceptedMouseButtons(Qt::LeftButton);
    setCursor(Qt::ArrowCursor);
}

void ClickablePixmap::mouseReleaseEvent( QGraphicsSceneMouseEvent* event )
{
    setCursor(Qt::ArrowCursor);
    m_pressed = false;
    update();
    if( boundingRect().contains(event->pos()) )
        emit clicked();
    event->accept();
}

void ClickablePixmap::mousePressEvent( QGraphicsSceneMouseEvent* event )
{
    setCursor(Qt::ArrowCursor);
    m_pressed = true;
    update();
    QGraphicsPixmapItem::mousePressEvent(event);
}

void ClickablePixmap::paint( QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget )
{
    Q_UNUSED(option);
    Q_UNUSED(widget);

    QRect rect(0,0, boundingRect().width(), boundingRect().height());

    // Create the pushed effet
    if( m_pressed ) {
        rect.adjust(2,2,-2,-2);
    }
    painter->drawPixmap(rect, pixmap());
}

次に行うことは、このウィジェットをコンテナウィジェットに埋め込むことです。

QVBoxLayout

次に、その下にQLabelを追加できます。

于 2012-12-21T23:17:00.407 に答える