سؤال

مطورو 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