Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Qt 在QGraphicsPixmap上显示许多PixMap,其下有一个QLabel_Qt_Text_Widget_Icons_Clickable - Fatal编程技术网

Qt 在QGraphicsPixmap上显示许多PixMap,其下有一个QLabel

Qt 在QGraphicsPixmap上显示许多PixMap,其下有一个QLabel,qt,text,widget,icons,clickable,Qt,Text,Widget,Icons,Clickable,我需要一个小部件,在那里我可以放置各种可点击的图标,并在这些图标下使用QLabel显示一些文本 这是一幅图像: 我知道这将需要一些调整和子分类。做这件事最好的方法是什么?我知道这些可点击的图标将显示在QGraphicsView上。我建议您使用QGraphicsView 下面是一个可单击的pixmap示例: ClickablePixmap::ClickablePixmap( QGraphicsItem* itemParent ) : QObject(0) , QGraphicsPi

我需要一个小部件,在那里我可以放置各种可点击的图标,并在这些图标下使用QLabel显示一些文本

这是一幅图像:


我知道这将需要一些调整和子分类。做这件事最好的方法是什么?我知道这些可点击的图标将显示在QGraphicsView上。

我建议您使用QGraphicsView

下面是一个可单击的pixmap示例:

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