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. QFrame with layout and comboBoxes insight => setStylesSheet calls index method of QAbstractItemModel of connected comboBoxes

QFrame with layout and comboBoxes insight => setStylesSheet calls index method of QAbstractItemModel of connected comboBoxes

Scheduled Pinned Locked Moved Solved General and Desktop
qframestylesheetperformanceqabstractitemmo
11 Posts 3 Posters 2.3k 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #2

    Hi,

    Can you provide a minimal compilable example that shows that behaviour ?

    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
    1
    • D Offline
      D Offline
      Dagginio
      wrote on last edited by
      #3

      Creating an example is rather time intensive, thus I do not want to do it now. My question was more about the general understanding, when the index and data method of QAbstractItemModels are called. I expected that this will happen only when you interact directly with the corresponding ComboBox/Listview. But obviously, this happens on much more situations. How to figure out what signals or evants will interact with the model.

      By the way, I am working with PyQt.

      Does this help a bit more?
      Daniel

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #4

        AFAIK, PyQt should have no impact on that.

        The high number of calls are indeed pretty surprising. What might happen is that there are several changes of sizes due to the change of style sheet. Not knowing how many combo boxes you have and what your GUI looks like, it's pretty much impossible to guess what is happening.

        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
        0
        • D Offline
          D Offline
          Dagginio
          wrote on last edited by
          #5

          Hey, sorry for my late reply.
          I also thought already that it might be because of the size change. So I tried already to keep the border width constant at 3px. However, just setting border-color in the style sheet does not have an effect (see last code snippet). I have to use the border property where I have to set the width, style and color. So I always have to set a new width and maybe even if I always keep 3px, it resets the with and recalculates the size of the content inside the frame.

          on enter event I use (CardInnerFrame is the name of the class I use. It is a subclass of QFrame)

          self.setStyleSheet("CardInnerFrame {"
                                     "border: 3px solid rgb(85,142,213);}")
          

          on leave I use:

          self.setStyleSheet("CardInnerFrame {"
                                     "border: 3px solid rgb(160,160,160);}")
          

          I would prefer to use to set only the color:

          self.setStyleSheet("CardInnerFrame {"
                                     "border-color: rgb(160,160,160);}")
          

          But that one has no effect.

          Thanks for your help.
          Daniel

          1 Reply Last reply
          0
          • D Offline
            D Offline
            Dagginio
            wrote on last edited by
            #6

            Ah ja, forgot to mention about the GUI. It is simply a frame with varying number of comboBoxes. But you realize a significant performance loss with let's say more than 5 comboBoxes in the the frame. Please find attached a screenshot of the frame.

            0_1535525613199_Frame.PNG

            1 Reply Last reply
            0
            • mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #7

              Hi
              If you suspect its due to stylesheet usage, you see this performance drop, why
              not just paint the effect yourself in paintEvent since u already subclassed the frame.
              it is very little code

                QStyleOptionFrame opt;
                  initStyleOption(&opt);
                  style()->drawControl(QStyle::CE_ShapedFrame, &opt, p, this);
              

              https://code.woboq.org/qt5/qtbase/src/widgets/widgets/qframe.cpp.html#_ZN6QFrame9drawFrameEP8QPainter

              D 1 Reply Last reply
              2
              • mrjjM mrjj

                Hi
                If you suspect its due to stylesheet usage, you see this performance drop, why
                not just paint the effect yourself in paintEvent since u already subclassed the frame.
                it is very little code

                  QStyleOptionFrame opt;
                    initStyleOption(&opt);
                    style()->drawControl(QStyle::CE_ShapedFrame, &opt, p, this);
                

                https://code.woboq.org/qt5/qtbase/src/widgets/widgets/qframe.cpp.html#_ZN6QFrame9drawFrameEP8QPainter

                D Offline
                D Offline
                Dagginio
                wrote on last edited by
                #8

                @mrjj Sorry that I did not answer for so long. Was totally busy with other important stuff that I could not further focus on this. But now I am back on this topic. I like the idea to simply paint it on my own. But actually I am a little bit over-strained with it. I never painted something on my own before, but I would really like to learn it.

                So, here is what I want to achieve. When I enter the frame, the grey frame should get blue plus I want to change the line width of the frame.

                What I have: A Class that subclasses the Qframe class where I reimplemented the enterEvent method, to catch the the events, when the mouse pointer enters the frame. What to do now? Creating a painter from QtGui.QPainter? The few lines you added did not help so much.

                I am using Qt for python, but I guess it will be more or less the same as in normal Qt, right? I appreciate your help.

                Daniel

                mrjjM 1 Reply Last reply
                0
                • D Dagginio

                  @mrjj Sorry that I did not answer for so long. Was totally busy with other important stuff that I could not further focus on this. But now I am back on this topic. I like the idea to simply paint it on my own. But actually I am a little bit over-strained with it. I never painted something on my own before, but I would really like to learn it.

                  So, here is what I want to achieve. When I enter the frame, the grey frame should get blue plus I want to change the line width of the frame.

                  What I have: A Class that subclasses the Qframe class where I reimplemented the enterEvent method, to catch the the events, when the mouse pointer enters the frame. What to do now? Creating a painter from QtGui.QPainter? The few lines you added did not help so much.

                  I am using Qt for python, but I guess it will be more or less the same as in normal Qt, right? I appreciate your help.

                  Daniel

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by mrjj
                  #9

                  @Dagginio
                  Hi
                  Using python should be exactly the same.
                  So in enterEvent you set a variable to know mouse has enter and clear
                  it on the leave event.
                  Then you override paintEvent
                  and there you make a QPainter and draw the frames the way you want.

                  (example) disclaimer. not a pyt user :)

                   def paintEvent(self, event):
                          painter = QPainter(self)
                          painter.drawLine(0, 10, 10, 10)
                  
                  D 1 Reply Last reply
                  1
                  • mrjjM mrjj

                    @Dagginio
                    Hi
                    Using python should be exactly the same.
                    So in enterEvent you set a variable to know mouse has enter and clear
                    it on the leave event.
                    Then you override paintEvent
                    and there you make a QPainter and draw the frames the way you want.

                    (example) disclaimer. not a pyt user :)

                     def paintEvent(self, event):
                            painter = QPainter(self)
                            painter.drawLine(0, 10, 10, 10)
                    
                    D Offline
                    D Offline
                    Dagginio
                    wrote on last edited by
                    #10

                    @mrjj thanks. That is what I was thinking of. However, when set a variable that the mouse entered, it will not trigger the painting itself. Is a event function callable? Can I call the paintEvent method from the enterEvent method? And assuming I painted already a blue frame. Do I have to remove that blue frame before I paint a grey one?

                    Daniel

                    mrjjM 1 Reply Last reply
                    0
                    • D Dagginio

                      @mrjj thanks. That is what I was thinking of. However, when set a variable that the mouse entered, it will not trigger the painting itself. Is a event function callable? Can I call the paintEvent method from the enterEvent method? And assuming I painted already a blue frame. Do I have to remove that blue frame before I paint a grey one?

                      Daniel

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by mrjj
                      #11

                      @Dagginio
                      Hi
                      just call update() to have it refresh when "status" changes.

                      -Do I have to remove that blue frame before I paint a grey one?
                      depends if you have autofillbackground on widget on.
                      in that case it will be cleared default.
                      else u might have to. try without and see

                      1 Reply Last reply
                      1

                      • Login

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