Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. QLabel is snipping after using SetStyleSheet
Forum Updated to NodeBB v4.3 + New Features

QLabel is snipping after using SetStyleSheet

Scheduled Pinned Locked Moved Solved Qt Creator and other tools
9 Posts 3 Posters 1.4k 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.
  • S Offline
    S Offline
    SHRED4RED
    wrote on last edited by
    #1

    I use QLabels in verticalLayout:
    QLabel* label;
    label->setWordWrap(true);
    label->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
    label->setMaximumWidth(250);
    label->setText(...);
    ...
    expected result: it's okey!
    ui->verticalLayout->addWidget(label, 0 , Qt::AlignBottom | Qt::AlignLeft)
    0_1527329215709_Without_style.PNG

    then I want to set the properties, for example:
    label->setStyleSheet("QLabel {background-color: rgb(255,255,255) }");
    result:
    0_1527329541787_snipping.PNG

    why snipping occurs and how to avoid it? Ty for help...

    raven-worxR 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      When using a style sheet, the concerned widgets are not rendered by the platform style plugin but by another one that supports style sheet, so the output might not be exactly what you are used to see from your OS.

      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
      • S SHRED4RED

        I use QLabels in verticalLayout:
        QLabel* label;
        label->setWordWrap(true);
        label->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
        label->setMaximumWidth(250);
        label->setText(...);
        ...
        expected result: it's okey!
        ui->verticalLayout->addWidget(label, 0 , Qt::AlignBottom | Qt::AlignLeft)
        0_1527329215709_Without_style.PNG

        then I want to set the properties, for example:
        label->setStyleSheet("QLabel {background-color: rgb(255,255,255) }");
        result:
        0_1527329541787_snipping.PNG

        why snipping occurs and how to avoid it? Ty for help...

        raven-worxR Offline
        raven-worxR Offline
        raven-worx
        Moderators
        wrote on last edited by
        #3

        @SHRED4RED
        is this really the only stylesheet declaration you set?!

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        S 1 Reply Last reply
        0
        • raven-worxR raven-worx

          @SHRED4RED
          is this really the only stylesheet declaration you set?!

          S Offline
          S Offline
          SHRED4RED
          wrote on last edited by
          #4

          @raven-worx
          Yes. only stylesheet:
          Okey, i all the same have the problem with snipping QLabel:

          code when I add QLabels:

          static int x = 1;
          
          label->setText(ui->lineEdit->text());
          ui->lineEdit->clear();
          label->setWordWrap(true);
          label->setStyleSheet("QLabel { background-color: rgb(0, 0, 0);"
                               "color: rgb(0, 200, 0);"
                               "font: 12pt \"Plantagenet Cherokee\";}"
                               );
          label->setTextFormat(Qt::RichText);
          
          QSizePolicy policy(QSizePolicy::Fixed , QSizePolicy::Fixed);
          label->setSizePolicy(policy);
          
          label->setAlignment(Qt::AlignLeft);
          label->setMaximumWidth(250);
          label->setMinimumHeight(label->sizeHint().height());
          
          if(x % 2 == 0)
          {
              ui->verticalLayout_2->addWidget(label,0, Qt::AlignLeft |  Qt::AlignBottom);
          
          }
          else
          {
              ui->verticalLayout_2->addWidget(label,0, Qt::AlignRight | Qt::AlignBottom);
          }
          
          ++x;
          

          what occurs when I resize MainWindow:
          0_1527496184897_1.PNG
          0_1527496201053_2.PNG

          scrollAreaWidgetCotents properties : SizeConstraint SetMinimumSize, sizePolicy: horizontal - Minimum, vertical - Maximum

          This problem occurs when I use Layout alignment ! If i don't use it QLabels doesn't snipped

          raven-worxR 1 Reply Last reply
          0
          • S SHRED4RED

            @raven-worx
            Yes. only stylesheet:
            Okey, i all the same have the problem with snipping QLabel:

            code when I add QLabels:

            static int x = 1;
            
            label->setText(ui->lineEdit->text());
            ui->lineEdit->clear();
            label->setWordWrap(true);
            label->setStyleSheet("QLabel { background-color: rgb(0, 0, 0);"
                                 "color: rgb(0, 200, 0);"
                                 "font: 12pt \"Plantagenet Cherokee\";}"
                                 );
            label->setTextFormat(Qt::RichText);
            
            QSizePolicy policy(QSizePolicy::Fixed , QSizePolicy::Fixed);
            label->setSizePolicy(policy);
            
            label->setAlignment(Qt::AlignLeft);
            label->setMaximumWidth(250);
            label->setMinimumHeight(label->sizeHint().height());
            
            if(x % 2 == 0)
            {
                ui->verticalLayout_2->addWidget(label,0, Qt::AlignLeft |  Qt::AlignBottom);
            
            }
            else
            {
                ui->verticalLayout_2->addWidget(label,0, Qt::AlignRight | Qt::AlignBottom);
            }
            
            ++x;
            

            what occurs when I resize MainWindow:
            0_1527496184897_1.PNG
            0_1527496201053_2.PNG

            scrollAreaWidgetCotents properties : SizeConstraint SetMinimumSize, sizePolicy: horizontal - Minimum, vertical - Maximum

            This problem occurs when I use Layout alignment ! If i don't use it QLabels doesn't snipped

            raven-worxR Offline
            raven-worxR Offline
            raven-worx
            Moderators
            wrote on last edited by raven-worx
            #5

            @SHRED4RED

            QSizePolicy policy(QSizePolicy::Fixed , QSizePolicy::Fixed);
            label->setSizePolicy(policy);

            What happens when you remove this?

            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
            If you have a question please use the forum so others can benefit from the solution in the future

            S 1 Reply Last reply
            1
            • raven-worxR raven-worx

              @SHRED4RED

              QSizePolicy policy(QSizePolicy::Fixed , QSizePolicy::Fixed);
              label->setSizePolicy(policy);

              What happens when you remove this?

              S Offline
              S Offline
              SHRED4RED
              wrote on last edited by
              #6

              @raven-worx
              If use default QLabel sizePolicy then snipping doesn't occur. But I can't understand what happen ... :(

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

                Because the size policy you are using explicitly disallows the widget to expand or shrink as needed.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                S 2 Replies Last reply
                0
                • SGaistS SGaist

                  Because the size policy you are using explicitly disallows the widget to expand or shrink as needed.

                  S Offline
                  S Offline
                  SHRED4RED
                  wrote on last edited by
                  #8

                  @SGaist
                  Okey i continue testing, and next test are:

                  1. just long text
                    0_1527501112500_3.PNG
                  2. after long text set empty string or shot string
                    0_1527501169339_4.PNG

                  it's occur if i use Fixed sizePolicy and if don't use it.
                  Why?

                  1 Reply Last reply
                  0
                  • SGaistS SGaist

                    Because the size policy you are using explicitly disallows the widget to expand or shrink as needed.

                    S Offline
                    S Offline
                    SHRED4RED
                    wrote on last edited by
                    #9

                    do you see empty area between QLabels? There are the text which are snipped.
                    If don't use RichText and use Fixed size policy , then all are good. But I nevertheless can't understand how are work this magic.

                    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