QT开发人员!是否有在下图上的Midarea的背景上添加图像的方法?

enter image description here

我知道我可以使用这样的东西

QImage img("logo.jpg");
mdiArea->setBackground(img);

但是我不需要在背景上重复我的图像。

谢谢!

有帮助吗?

解决方案

正如我在上面的评论中所说的那样,您可以将 QMdiArea, ,覆盖它 paintEvent() 功能并自己绘制徽标图像(在右下角)。这是实现上述想法的示例代码:

class MdiArea : public QMdiArea
{
public:
    MdiArea(QWidget *parent = 0)
        :
            QMdiArea(parent),
            m_pixmap("logo.jpg")
    {}
protected:
    void paintEvent(QPaintEvent *event)
    {
        QMdiArea::paintEvent(event);

        QPainter painter(viewport());

        // Calculate the logo position - the bottom right corner of the mdi area.
        int x = width() - m_pixmap.width();
        int y = height() - m_pixmap.height();
        painter.drawPixmap(x, y, m_pixmap);
    }
private:
    // Store the logo image.
    QPixmap m_pixmap;
};

最后在主窗口中使用自定义MDI区域:

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    QMainWindow mainWindow;
    QMdiArea *mdiArea = new MdiArea(&mainWindow);
    mainWindow.setCentralWidget(mdiArea);
    mainWindow.show();

    return app.exec();
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top