Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED]Defining QMdiArea background
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]Defining QMdiArea background

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 10.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mbnoimi
    wrote on last edited by
    #1

    Hello folks,

    I want to add background image for QMdiArea but without tiling the image, how can I do that?

    PS

    • I tried to use setBackground(img) but it appears tiled background!
      !http://i.imgur.com/Aj8qs.png(test)!
    • I tried to use styleSheet but it shows the image in subWindows instead of Mdi area
      @background-image: url(:/img/gnome-graphics.png);
      background-repeat : no-repeat;@
      !http://i.imgur.com/lvzjE.png(test)!
    1 Reply Last reply
    0
    • S Offline
      S Offline
      sigrid
      wrote on last edited by
      #2

      The following "FAQ":http://developer.qt.nokia.com/faq/answer/when_setting_a_background_pixmap_for_a_widget_it_is_tiled_if_the_pixmap_is_ suggests a way of achieving this by reimplementing the resizeEvent() and scaling the image.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mbnoimi
        wrote on last edited by
        #3

        Thanks a lot (I didn't notice that answer although I used search option).

        I modified the answer a little bit.
        @#ifndef MDIAREA_H
        #define MDIAREA_H

        #include <QMdiArea>
        #include <QResizeEvent>
        #include <QPainter>

        class MdiArea : public QMdiArea
        {
        Q_OBJECT
        public:
        MdiArea(/*QMdiArea clone, */QImage backgroundImage, QBrush backgroundBrush)
        {
        i = backgroundImage;
        b = backgroundBrush;
        }
        protected:
        void resizeEvent(QResizeEvent *resizeEvent)
        {
        QImage newBackground(resizeEvent->size(), QImage::Format_ARGB32_Premultiplied);
        QPainter p(&newBackground);
        p.fillRect(newBackground.rect(), b);

            QImage scaled = i.scaled(resizeEvent->size(),Qt::KeepAspectRatio);
            QRect scaledRect = scaled.rect();
            scaledRect.moveCenter(newBackground.rect().center());
            p.drawImage(scaledRect, scaled);
            setBackground(newBackground);
            QMdiArea::resizeEvent(resizeEvent);
        }
        

        private:
        QImage i;
        QBrush b;
        };

        #endif // MDIAREA_H@

        I tried to use that implementation for passing QMdiArea as a copy but it didn't' work because " QMdiArea::QMdiArea(const QMdiArea&) is private"
        @ui->mdiArea = new MdiArea(MdiArea(QImage(":/img/gnome-graphics.png"), Qt::red)); // mdiArea is QMdiArea object@

        How can I fix this issue?

        1 Reply Last reply
        0
        • S Offline
          S Offline
          sigrid
          wrote on last edited by
          #4

          Can you give some more details on what exactly you want to do? Have you created a QMdiArea in Designer and want to use it together with the QMdiArea subclass that was created in code? If so, you can simply "promote ":http://doc.qt.nokia.com/latest/designer-using-custom-widgets.html#promoting-widgets the QMdiArea in Designer to your subclass.

          Creating a copy of the QMdiArea is not possible. It is not possible to create copies of QObjects and their subclasses for the reasons outlined in this "FAQ":http://developer.qt.nokia.com/faq/answer/why_is_it_not_allowed_to_copy_qobjects. Instead, you can follow the advice listed "here":https://developer.qt.nokia.com/faq/answer/how_can_i_clone_a_widget if you need to clone a widget

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mbnoimi
            wrote on last edited by
            #5

            [quote]Have you created a QMdiArea in Designer and want to use it together with the QMdiArea subclass that was created in code? If so, you can simply promote [doc.qt.nokia.com] the QMdiArea in Designer to your subclass.[/quote]
            Yes exactly but I couldn't find QMdiArea in base class drop list of Promoted widgets window!

            [quote]Can you give some more details on what exactly you want to do?[/quote]
            you can test my trial at [url=http://www.mediafire.com/file/9rebbbdumq982df/MDITest.zip]this link[/url] (it's tiny test don't be afraid).

            PS
            I'm wondering why these forums don't allow to post attachments this is really sucks.

            1 Reply Last reply
            0
            • G Offline
              G Offline
              giesbert
              wrote on last edited by
              #6

              [quote author="mbnoimi" date="1311689985"]PS
              I'm wondering why these forums don't allow to post attachments this is really sucks.[/quote]

              There were many discussions about that, but the result was, it is complicated due to legal issues.

              Nokia Certified Qt Specialist.
              Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

              1 Reply Last reply
              0
              • M Offline
                M Offline
                mbnoimi
                wrote on last edited by
                #7

                Guys could you please help me... I couldn't fix this issue.

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  sigrid
                  wrote on last edited by
                  #8

                  The QMdiArea is indeed not listed among the promoted widgets. I checked the reason for this with our developers here and QMdiArea is put in an exclude list since it is a container that it is problematic to promote. I see that you are investigating a way around this in this "thread":http://developer.qt.nokia.com/forums/viewthread/8334, and that sounds like a viable approach since QFrame is a container as well.

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved