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. Window with custom background and modify the content area.

Window with custom background and modify the content area.

Scheduled Pinned Locked Moved Solved General and Desktop
custom windowcustom widgetcontent margins
8 Posts 3 Posters 2.9k Views
  • 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.
  • G Offline
    G Offline
    GranVeoDuendes
    wrote on 24 Aug 2017, 03:36 last edited by
    #1

    I need your help. I want to create a window, inherited from QMainWindow or QDialog. This window will have a fully customized background and text. To draw rewrite the event paintEvent, this without problems. The problem, as I can modify the area where it will represent the contents of the window, widgets, not to draw above the text.

    0_1503545497867_esquema.jpg
    In a bad way, I've resized the content within the paintEvent event . This way is bad but half working.

        layout = self.layout()
        if layout is not None:
            rect = layout.geometry()
            rect.setY(tempHeight)
            layout.setGeometry(rect)
    

    The problems have come when I tried to do the same with MDI windows and especially the QTabWidget widget.

    Thanks in advance for the answers. And if you can help me.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 24 Aug 2017, 06:34 last edited by
      #2

      Hi,

      Do you mean you would like to have some margin around your "central widget" as to show your fancy background ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • G Offline
        G Offline
        GranVeoDuendes
        wrote on 24 Aug 2017, 15:39 last edited by
        #3

        Exactly, I need to modify dimensions and position of the center widget and increase the size of the window with the fantasy border and other elements that are drawn in the custom background.

        I made a new drawing that clarifies it.
        0_1503589117337_esquema2.png

        PS: The solution can be in C++ as in Python. The question is, solve it.
        Thank you.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 24 Aug 2017, 15:57 last edited by mrjj
          #4

          Hi
          You can use a layout and the layouts Content Margins
          http://doc.qt.io/qt-5/qlayout.html#setContentsMargins

          That way you reserve the space and the inner widget will be automatically fitted.
          alt text

          1 Reply Last reply
          1
          • G Offline
            G Offline
            GranVeoDuendes
            wrote on 24 Aug 2017, 17:05 last edited by
            #5

            Thanks mrjj.
            I know what you tell me and I used to have it before. But now I need all source code:

            QDialog -> inheriting a class and that does that work

            Without using the designer at any time. There are many types of dialogues that I have.
            So everything, you gave me an idea, modify the margins by source code.

            Thank you very much, today, if I take time, I try and I tell you.

            M 1 Reply Last reply 24 Aug 2017, 17:10
            0
            • G GranVeoDuendes
              24 Aug 2017, 17:05

              Thanks mrjj.
              I know what you tell me and I used to have it before. But now I need all source code:

              QDialog -> inheriting a class and that does that work

              Without using the designer at any time. There are many types of dialogues that I have.
              So everything, you gave me an idea, modify the margins by source code.

              Thank you very much, today, if I take time, I try and I tell you.

              M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 24 Aug 2017, 17:10 last edited by mrjj
              #6

              @GranVeoDuendes
              Hi
              You do not need to use Designer at all.
              This you can also do in pure code with a FancyDialog subclass.
              And give that a function like
              addContentWidget that makes sure its inserted into the inner layout in correct way.

              But is each dialog dynamic and u add different content or is each dialog static and you just have many different ?

              I had a design where i need the Dialogs to have a Header & Footer element.
              So I made a subclass Dialog for that, so it would have these element pr default
              and simply gave it a UI file to load as content.
              So you can use Designer for the actual widgets if you want
              and still have a new type of window giving a custom background.

              1 Reply Last reply
              1
              • G Offline
                G Offline
                GranVeoDuendes
                wrote on 24 Aug 2017, 17:26 last edited by
                #7

                Change icons, decoration, and title. I thought about making a widget and I did not like the first tests.

                This is an actual capture of my application.

                0_1503595531434_Screenshot_20170824_022422.png

                The left side, with the icon and titles is part of that fancy background. I have the methods to assign icon and texts that I put in the constructor. If I assign more icons and more texts there are more columns.

                But the idea of modifying, in the assignment properties of the icons and texts, using a method that modifies the margins, is a very good idea and I think it will work. I try to get home.

                Thank you.

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  GranVeoDuendes
                  wrote on 25 Aug 2017, 00:20 last edited by GranVeoDuendes
                  #8

                  Perfect. Thank you very much. It works perfect.

                  So that other people, if they have the same problem here have the solution. It's very simple and I did not fall for something so simple. In the properties where I assign the texts and icons we call a method that modifies the margins. Only that.

                  For example:

                  #import PyQt5 or PySide (To the taste of the client)
                  
                  class Test(QDialog):
                      def __init__(self, parent: QDialog = None):
                          super().__init__(parent)
                          self.__row_Text = None
                  
                      @property
                      def row_Text(self) -> str:
                          return self.__row_Text
                  
                      @row_Text.setter
                      def row_Text(self, value: str):
                          self.__row_Text = value
                          self.updateFancyBackground()
                          self.repaint()
                  
                       def updateFancyBackground(self):
                          # I liked the name Fancy Background
                          if self.__row_Text is not None:
                              margins = self.layout().contentsMargins()
                              margins.setTop(24)
                              self.layout().setContentsMargins(margins)
                  
                      def paintEvent(self, event: QPaintEvent):
                          # Your code for height = 24
                          pass
                  

                  Many thanks to "SGaist" and "mrjj", for giving me the idea to solve it.

                  1 Reply Last reply
                  1

                  1/8

                  24 Aug 2017, 03:36

                  • Login

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