Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Qt 6
  4. Why there is a line on my dialog?
Forum Updated to NodeBB v4.3 + New Features

Why there is a line on my dialog?

Scheduled Pinned Locked Moved Solved Qt 6
11 Posts 4 Posters 1.2k Views 3 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.
  • Chris KawaC Offline
    Chris KawaC Offline
    Chris Kawa
    Lifetime Qt Champion
    wrote on last edited by
    #2

    In resizeEvent use the size that comes with the event: e->size() instead of width()/height().

    When overriding events don't forget to call base implementation or you might experience glitches.

    QSize is the same size as a pointer so it's no less performant and a lot safer to pass it by value, or, if you don't want to do that, then by const reference.

    C 1 Reply Last reply
    3
    • Chris KawaC Chris Kawa

      In resizeEvent use the size that comes with the event: e->size() instead of width()/height().

      When overriding events don't forget to call base implementation or you might experience glitches.

      QSize is the same size as a pointer so it's no less performant and a lot safer to pass it by value, or, if you don't want to do that, then by const reference.

      C Offline
      C Offline
      Christina123
      wrote on last edited by Christina123
      #3
      void window::resizeEvent(QResizeEvent *e)
      {
          Q_UNUSED(e);
          QSize windowSize = e->size();
          emit resized(windowSize);
      }
      void Receiver::resizeWindow(QSize size)
      {
          resize(size);
      }
      

      Despite changing the code to the code above, the line still appears on the window. It seems that by simply connecting these two dialogs will result in the appearance of line which I have no clue why is that.

      1 Reply Last reply
      0
      • Chris KawaC Offline
        Chris KawaC Offline
        Chris Kawa
        Lifetime Qt Champion
        wrote on last edited by
        #4

        You skipped the middle part :) Call base implementation of resizeEvent. I don't know the base implementation, but I would suspect it causes update and subsequent repaint of the window. Your receiver probably has a position slightly offset from the top and if you don't call base resizeEvent that part is not repainted.

        Also e is now used so you don't need Q_UNUSED anymore.

        1 Reply Last reply
        2
        • C Offline
          C Offline
          Christina123
          wrote on last edited by
          #5

          Even though I mark the function in the class as void resizeEvent(QResizeEvent *e) override; which I think is what you mean by overriding the base class , there is still a line appearing on the screen.

          mrjjM 1 Reply Last reply
          0
          • C Christina123

            Even though I mark the function in the class as void resizeEvent(QResizeEvent *e) override; which I think is what you mean by overriding the base class , there is still a line appearing on the screen.

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

            @Christina123

            Hi
            The override keyword just makes the compiler complain if you do not override anything . (misspelled name, parameters wrong etc)

            You still need to call the "original" code which we talk about as " Call base implementation"

            In code it would be something like

            void window::resizeEvent(QResizeEvent *e)
            {
            QSize windowSize = e->size();
            emit resized(windowSize);
            QMainWindow::resizeEvent(e); // calling the code we "overrode"
            }

            This assumes that your class window is a subclass of QMainWindow.
            Else the " QMainWindow::" part should be replaced with the real base class name.

            1 Reply Last reply
            2
            • C Offline
              C Offline
              Christina123
              wrote on last edited by
              #7

              Thank you for your reply. Despite that I call the base implementation the line still appears...

              /*My code now*/
              void window::resizeEvent(QResizeEvent *e)
              {
                  QSize windowSize = e->size();
                  emit resized(windowSize);
                  QDialog::resizeEvent(e);
              }
              
              1 Reply Last reply
              0
              • S Offline
                S Offline
                SimonSchroeder
                wrote on last edited by
                #8

                Can you explain a little more what you are trying to achieve? Are your window and Receiver objects two separate windows? Or is one contained within the other?

                And from which Qt classes are window and Receiver derived?

                C 1 Reply Last reply
                0
                • S SimonSchroeder

                  Can you explain a little more what you are trying to achieve? Are your window and Receiver objects two separate windows? Or is one contained within the other?

                  And from which Qt classes are window and Receiver derived?

                  C Offline
                  C Offline
                  Christina123
                  wrote on last edited by
                  #9

                  @SimonSchroeder Hi, window and sender are two separate dialogs and there is no parent-child relation between them. However, they are connected through signals and slots. What I want to do here is when I resize the window dialog, which is the main interface between the user and the program, the receiver dialog will be automatically resized. The problem here is that a line suddenly appears on my window dialog not my receiver's when I add this line QObject::connect(&w, &Sender::resized, &receiverWindow, &Receiver::resizeWindow); to my code. Please tell me if you need more code to debug this. Thank you :)

                  1 Reply Last reply
                  0
                  • C Offline
                    C Offline
                    Christina123
                    wrote on last edited by
                    #10

                    I was being very stupid here, the line appears on my screen is actually a QRect which I accidently draw it in paintevent. Sorry for taking up your guys time to solve this issue.

                    mrjjM 1 Reply Last reply
                    4
                    • C Christina123

                      I was being very stupid here, the line appears on my screen is actually a QRect which I accidently draw it in paintevent. Sorry for taking up your guys time to solve this issue.

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

                      @Christina123

                      Well it was good you found it. No worries.
                      Calling the base version is ultra important in most cases when using Qt so
                      if you walk away with that knowledge extra, it was all worth it :)

                      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