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. qlabel border radius stylesheet
Forum Updated to NodeBB v4.3 + New Features

qlabel border radius stylesheet

Scheduled Pinned Locked Moved Solved General and Desktop
15 Posts 5 Posters 36.2k 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.
  • U user4592357
    const auto entryLabel = new QLabel { entryText, this };
    entryLabel->setStyleSheet("margin-left: 10px; border-radius: 25px; background: white; color: #4A0C46;");
    m_pEntriesLayout->addWidget(entryLabel, 0, Qt::AlignCenter);
    
    joeQJ Offline
    joeQJ Offline
    joeQ
    wrote on last edited by
    #5

    @user4592357 Hi,friend. Welcome.

    Try below snippet:

    entryLabel->setStyleSheet("QLabel{margin-left: 10px; border-radius: 25px; background: white; color: #4A0C46;}");
    

    Just do it!

    U 1 Reply Last reply
    1
    • joeQJ joeQ

      @user4592357 Hi,friend. Welcome.

      Try below snippet:

      entryLabel->setStyleSheet("QLabel{margin-left: 10px; border-radius: 25px; background: white; color: #4A0C46;}");
      
      U Offline
      U Offline
      user4592357
      wrote on last edited by
      #6

      @joeQ i had tried that too.

      @Taz742, doesn't work for me

      i'm placing the label in one of QStackedWidget's widget, which is a member in a QWidget subclass, and on that subclass i set style sheet too. i thought that was the problem, but i added the border-radius part to that style sheet and it still doesn't work

      1 Reply Last reply
      0
      • U user4592357
        const auto entryLabel = new QLabel { entryText, this };
        entryLabel->setStyleSheet("margin-left: 10px; border-radius: 25px; background: white; color: #4A0C46;");
        m_pEntriesLayout->addWidget(entryLabel, 0, Qt::AlignCenter);
        
        J.HilkJ Online
        J.HilkJ Online
        J.Hilk
        Moderators
        wrote on last edited by
        #7

        @user4592357
        whats the actuall size of the Label? if its below 50 pxl, no rounded corners will be drawn, also you'll most likly need to specify a border color:

        this for example, works fine for me

        const auto entryLabel = new QLabel { "Blablabla"};
            entryLabel->setStyleSheet("margin-left: 10px; border: 1px solid black; border-radius: 25px; background: white; color: red;");
            entryLabel->show();
            entryLabel->resize(100,100);
        

        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        U 1 Reply Last reply
        1
        • J.HilkJ J.Hilk

          @user4592357
          whats the actuall size of the Label? if its below 50 pxl, no rounded corners will be drawn, also you'll most likly need to specify a border color:

          this for example, works fine for me

          const auto entryLabel = new QLabel { "Blablabla"};
              entryLabel->setStyleSheet("margin-left: 10px; border: 1px solid black; border-radius: 25px; background: white; color: red;");
              entryLabel->show();
              entryLabel->resize(100,100);
          
          U Offline
          U Offline
          user4592357
          wrote on last edited by
          #8

          @J.Hilk didn't work for me. and i set no size but the text is long enough (def larger than 50px)

          J.HilkJ 1 Reply Last reply
          0
          • U user4592357

            @J.Hilk didn't work for me. and i set no size but the text is long enough (def larger than 50px)

            J.HilkJ Online
            J.HilkJ Online
            J.Hilk
            Moderators
            wrote on last edited by
            #9

            @user4592357 height also > 50?


            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            U 1 Reply Last reply
            0
            • J.HilkJ J.Hilk

              @user4592357 height also > 50?

              U Offline
              U Offline
              user4592357
              wrote on last edited by
              #10

              @J.Hilk i set (100, 100) as you and didn't get any result

              J.HilkJ 1 Reply Last reply
              0
              • U user4592357

                @J.Hilk i set (100, 100) as you and didn't get any result

                J.HilkJ Online
                J.HilkJ Online
                J.Hilk
                Moderators
                wrote on last edited by
                #11

                @user4592357 my example was explicitly without parent, for testing purpose.
                If your label is managed by anything else, a Layout for example, entryLabel->resize(100,100); has quite literly no effect on your label.


                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                Q: What's that?
                A: It's blue light.
                Q: What does it do?
                A: It turns blue.

                U 1 Reply Last reply
                1
                • J.HilkJ J.Hilk

                  @user4592357 my example was explicitly without parent, for testing purpose.
                  If your label is managed by anything else, a Layout for example, entryLabel->resize(100,100); has quite literly no effect on your label.

                  U Offline
                  U Offline
                  user4592357
                  wrote on last edited by
                  #12

                  @J.Hilk yes, it's in a layout. so what should i do?

                  mrjjM 1 Reply Last reply
                  0
                  • U user4592357

                    @J.Hilk yes, it's in a layout. so what should i do?

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

                    @user4592357
                    You can use label->setMinimumSize(QSize(100,100));

                    U 1 Reply Last reply
                    3
                    • mrjjM mrjj

                      @user4592357
                      You can use label->setMinimumSize(QSize(100,100));

                      U Offline
                      U Offline
                      user4592357
                      wrote on last edited by
                      #14

                      @mrjj finally works, thanks!

                      mrjjM 1 Reply Last reply
                      0
                      • U user4592357

                        @mrjj finally works, thanks!

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

                        @user4592357
                        Super
                        It also fooled me in the beginning.
                        As soon as a Widget is in a layout, resize or setGeometry have no effect but
                        min/max size and SizePolicy is used instead.

                        1 Reply Last reply
                        2

                        • Login

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