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. QTextEdit doesn't display its corner with border-radius

QTextEdit doesn't display its corner with border-radius

Scheduled Pinned Locked Moved Unsolved General and Desktop
qtexteditborder-radius
11 Posts 4 Posters 7.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.
  • T Offline
    T Offline
    Toufi
    wrote on last edited by
    #1

    Hello,
    My problem is that I can't make my subclass of QTextEdit have rounded borders.
    Because when I use the stylesheet property border-radius, the corners are not displayed.

    // In my TextEdit constructor :
    setStyleSheet("border: 1px solid; border-radius:10px;");
    

    ScreenShot
    I use Windows 10 with Qt5.5.1
    I hope you will be able to help me...
    (and sorry for the bad english, I'm french ^^)

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

      Hi, welcome to devnet.

      Looks like a small bug in the way stylesheets are applied. You can workaround it by explicitly setting a background color:

      setStyleSheet("border: 1px solid; border-radius:10px; background-color: palette(base); ");
      
      T GaoboG funwayF 3 Replies Last reply
      4
      • Chris KawaC Chris Kawa

        Hi, welcome to devnet.

        Looks like a small bug in the way stylesheets are applied. You can workaround it by explicitly setting a background color:

        setStyleSheet("border: 1px solid; border-radius:10px; background-color: palette(base); ");
        
        T Offline
        T Offline
        Toufi
        wrote on last edited by
        #3

        @Chris-Kawa It works ! Thanks for all ^^

        1 Reply Last reply
        0
        • Chris KawaC Chris Kawa

          Hi, welcome to devnet.

          Looks like a small bug in the way stylesheets are applied. You can workaround it by explicitly setting a background color:

          setStyleSheet("border: 1px solid; border-radius:10px; background-color: palette(base); ");
          
          GaoboG Offline
          GaoboG Offline
          Gaobo
          wrote on last edited by
          #4

          @Chris-Kawa Why is it useless to set border-radius for QTextEdit without setting a background? It's confusing to me.

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

            Apparently changing just border radius does not internally trigger changing a style from the native one to stylesheets. Like I said - could be a bug. Have a look at the source code of QWidget and setStyleSheet if you're interested.

            GaoboG 1 Reply Last reply
            0
            • Chris KawaC Chris Kawa

              Apparently changing just border radius does not internally trigger changing a style from the native one to stylesheets. Like I said - could be a bug. Have a look at the source code of QWidget and setStyleSheet if you're interested.

              GaoboG Offline
              GaoboG Offline
              Gaobo
              wrote on last edited by
              #6

              @Chris-Kawa Thanks. But why it is useful for QLabel.

              Chris KawaC 1 Reply Last reply
              0
              • GaoboG Gaobo

                @Chris-Kawa Thanks. But why it is useful for QLabel.

                Chris KawaC Offline
                Chris KawaC Offline
                Chris Kawa
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @Gaobo Sorry, I don't understand the question. Why is it useful? It's your label. How should I know why it is useful to you?

                GaoboG 1 Reply Last reply
                0
                • Chris KawaC Chris Kawa

                  @Gaobo Sorry, I don't understand the question. Why is it useful? It's your label. How should I know why it is useful to you?

                  GaoboG Offline
                  GaoboG Offline
                  Gaobo
                  wrote on last edited by
                  #8

                  @Chris-Kawa Sorry for my poor expresson. I mean, it's useful that I only set the border-radius for QLabel and not the background.

                  1 Reply Last reply
                  0
                  • Chris KawaC Chris Kawa

                    Hi, welcome to devnet.

                    Looks like a small bug in the way stylesheets are applied. You can workaround it by explicitly setting a background color:

                    setStyleSheet("border: 1px solid; border-radius:10px; background-color: palette(base); ");
                    
                    funwayF Offline
                    funwayF Offline
                    funway
                    wrote on last edited by
                    #9

                    @Chris-Kawa
                    I found QScrollArea has the same question, but explicitly setting a background color does not work for QScrollArea.

                    QScrollArea {
                         border: 1px solid silver;
                         border-radius: 10px;
                         background-color: palette(base);
                    }
                    

                    SCR-20230511-tldk.png

                    Could you please give me some tips on this? Thanks.

                    Chris KawaC 1 Reply Last reply
                    0
                    • funwayF funway

                      @Chris-Kawa
                      I found QScrollArea has the same question, but explicitly setting a background color does not work for QScrollArea.

                      QScrollArea {
                           border: 1px solid silver;
                           border-radius: 10px;
                           background-color: palette(base);
                      }
                      

                      SCR-20230511-tldk.png

                      Could you please give me some tips on this? Thanks.

                      Chris KawaC Offline
                      Chris KawaC Offline
                      Chris Kawa
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      @funway It's a bit different issue. Setting border radius does not clip children painting to the rounded corners of the parent (I'm guessing for performance reasons).
                      Scroll area has a viewport widget and (optionally) scrollbars that stick to the edges of it, so they will always cover the parent's rounded corners.

                      The easiest I think would be to disable the scroll area's border entirely and place it in a container widget that has border with rounded corners and matching content margins set. This of course means that you would get a bit of empty space around the scroll area.

                      If that's not an option you could maybe add a transparent for input widget on top of the scroll area (or 4 small ones in the corners) and draw the rounded corners in it. That should get you what you want but is a bit more work. Note that the rounded corner would cover scrollbars, which in some styles might not look too good.

                      funwayF 1 Reply Last reply
                      0
                      • Chris KawaC Chris Kawa

                        @funway It's a bit different issue. Setting border radius does not clip children painting to the rounded corners of the parent (I'm guessing for performance reasons).
                        Scroll area has a viewport widget and (optionally) scrollbars that stick to the edges of it, so they will always cover the parent's rounded corners.

                        The easiest I think would be to disable the scroll area's border entirely and place it in a container widget that has border with rounded corners and matching content margins set. This of course means that you would get a bit of empty space around the scroll area.

                        If that's not an option you could maybe add a transparent for input widget on top of the scroll area (or 4 small ones in the corners) and draw the rounded corners in it. That should get you what you want but is a bit more work. Note that the rounded corner would cover scrollbars, which in some styles might not look too good.

                        funwayF Offline
                        funwayF Offline
                        funway
                        wrote on last edited by
                        #11

                        @Chris-Kawa Wow! Thanks for your detailed reply. I will try it. 🙏

                        1 Reply Last reply
                        0
                        • I isudfv referenced this topic on

                        • Login

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