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. Weird Rendering
Forum Updated to NodeBB v4.3 + New Features

Weird Rendering

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 413 Views 2 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.
  • ModelTechM Offline
    ModelTechM Offline
    ModelTech
    wrote on last edited by
    #1

    I am trying to debug a rendering problem. At this moment, I have however no clue in which direction I should be looking and hence also have no idea yet how to isolate the problem and make a reproducable small example. The difficulty is also that it does not happend for all instances of the involved Widget class. Hopefully, somebody has a suggestion for me...

    I have QGridLayout to which I add Widgets dynamically, i.e., by means of some function that I named repopulate(). This function is called upon creation of a Widget including a QScrollArea that includes the QGridLayout. This repopulate() function is called again when the content of the QGridLayout needs to be changed. In such case, the content of the QGridLayout is rebuild from scratch by first deleting all existing Widgets in the QGridLayout and subsequently repopulating the QGridLayout (I am aware that this is not necessarily the best approach, but it is the easiest to implement and I have done it in this way many times before without problems). The fact that the QGridLyout is used within a QScrollArea is potentially part of the problem. For some reason, the Widgets in the QGridLayout are not rendered correctly in some cases when repopulate() is called in the constructor of the Widget containing the QScrollArea that includes the QGridLayout. It is strange that it does not happen for all instances of the Widget.

    Unfortunately, I cannot share a full screendump or actual code, but this is the undesired rendering effect. It shows that the size of the QLabels at the top line and the QLineEdits and other Widgets below the top line is compute incorrectly.
    WeirdRendering.png

    Any ideas in which direction I should look to identify what causes this weird rendering?

    The code is Qt5-based and the problem appears on both Linux and Windows.

    Pl45m4P 1 Reply Last reply
    0
    • ModelTechM ModelTech

      I am trying to debug a rendering problem. At this moment, I have however no clue in which direction I should be looking and hence also have no idea yet how to isolate the problem and make a reproducable small example. The difficulty is also that it does not happend for all instances of the involved Widget class. Hopefully, somebody has a suggestion for me...

      I have QGridLayout to which I add Widgets dynamically, i.e., by means of some function that I named repopulate(). This function is called upon creation of a Widget including a QScrollArea that includes the QGridLayout. This repopulate() function is called again when the content of the QGridLayout needs to be changed. In such case, the content of the QGridLayout is rebuild from scratch by first deleting all existing Widgets in the QGridLayout and subsequently repopulating the QGridLayout (I am aware that this is not necessarily the best approach, but it is the easiest to implement and I have done it in this way many times before without problems). The fact that the QGridLyout is used within a QScrollArea is potentially part of the problem. For some reason, the Widgets in the QGridLayout are not rendered correctly in some cases when repopulate() is called in the constructor of the Widget containing the QScrollArea that includes the QGridLayout. It is strange that it does not happen for all instances of the Widget.

      Unfortunately, I cannot share a full screendump or actual code, but this is the undesired rendering effect. It shows that the size of the QLabels at the top line and the QLineEdits and other Widgets below the top line is compute incorrectly.
      WeirdRendering.png

      Any ideas in which direction I should look to identify what causes this weird rendering?

      The code is Qt5-based and the problem appears on both Linux and Windows.

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by Pl45m4
      #2

      @ModelTech said in Weird Rendering:

      The fact that the QGridLyout is used within a QScrollArea is potentially part of the problem

      That's a strange setup anyway. You usually don't want to add a layout to a QScrollArea. You add a content widget, which should be scrolled instead.
      I guess doing what you did, messes with the sizeHints and / or the widgets don't get the chance to expand.

      What happens if you show the same layout outside of the QScrollArea? If it renders correctly, it's not a render issue, but, as I assumed above, a layout (or design) issue. Fix that and it should work.


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      1 Reply Last reply
      0
      • ModelTechM Offline
        ModelTechM Offline
        ModelTech
        wrote on last edited by
        #3

        Thanks for your message. There is of course a Widget in between, otherwise it can't work at all. What I didn't do is subclass QScrollArea. But I will try to do so and see whether that solves the problem :)

        Pl45m4P 1 Reply Last reply
        0
        • ModelTechM ModelTech

          Thanks for your message. There is of course a Widget in between, otherwise it can't work at all. What I didn't do is subclass QScrollArea. But I will try to do so and see whether that solves the problem :)

          Pl45m4P Offline
          Pl45m4P Offline
          Pl45m4
          wrote on last edited by
          #4

          @ModelTech said in Weird Rendering:

          What I didn't do is subclass QScrollArea

          Who said that this is a good idea?!

          Are you able to display the content as desired if you resize the window?
          Does it expand and give more space to the QLineEdit, in order to be rendered correctly


          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

          ~E. W. Dijkstra

          1 Reply Last reply
          0
          • C Offline
            C Offline
            ChrisW67
            wrote on last edited by
            #5

            Can you break this code?

                Widget::Widget(QWidget *parent)
                    : QWidget(parent)
                {
                    QVBoxLayout *layout = new QVBoxLayout(this);
                    QScrollArea *scrollarea = new QScrollArea(this);
                    layout->addWidget(scrollarea);
                
                    QWidget *content = new QWidget(scrollarea);
                    content->setSizePolicy(QSizePolicy::Policy::Fixed, QSizePolicy::Policy::Fixed);
                    QGridLayout *grid = new QGridLayout(content);
                    for (int col = 0; col < 10; ++col) {
                        QLabel *label = new QLabel(QString("R0C%1").arg(col), content);
                        grid->addWidget(label, 0, col);
                    }
                    for (int row = 1; row < 30; ++row) {
                        for (int col = 0; col < 10; ++col) {
                            QLineEdit *edit = new QLineEdit(content);
                            edit->setText(QString("R%1C%2").arg(row).arg(col));
                            grid->addWidget(edit, row, col);
                        }
                    }
                    scrollarea->setWidget(content);
                
                    resize(800, 600);
                }
             
            

            04da518b-f418-4f31-a261-416e20f0bafc-image.png

            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