문제

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