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. [SOLVED] Hi, again :D Problem with Layouts...
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Hi, again :D Problem with Layouts...

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 5.1k Views 1 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.
  • Z Offline
    Z Offline
    zveljkovic
    wrote on last edited by
    #1

    I got to the problem where external style sheets (set with qApp->setStyleSheet("...")) can't apply linear gradient to background image of QLabel control. I am going for workaround to my custom control (base QFrame - Grid Layout;made in designer) contains another QFrame (Grid) which now contains QLabel. Extra QFrame is used to set border radius and gradient while QLabel will have transparent background. With this solution i overcome the problem of directly setting background gradient on QLabel.

    Now the problem is (sry i am new to Qt) how to setup sizePolicy of QFrames (outer & inner) and QLabel's to allow the label to expand the layouts (or maybe some other solution). I want to make a control that will contain one line of centered text on gradient background with border and some padding.

    I could go with QPushButton but i thought that the label has smaller memory/cpu requirements and i could have a lot of these elements around ( ~ 40 ).

    Also is there a way to set custom pseudo styles on controls? I mean to have MyCustomControl style and MyCustomControl:highlighted style and to switch between them by lets say some "obj->setPseudoStyle('highlighted', true)" or alike function?

    Thanks for help!!!

    Edit:
    I closed window with bug explanation (my 1st paragraph) so i couldn't supply link, but it is occurring only on windows.

    1 Reply Last reply
    0
    • F Offline
      F Offline
      Franzk
      wrote on last edited by
      #2

      Before you start trying to optimize your code, you should make it work. So you can try to get your desired solution with the label, but if a push button is easier, by all means use the push button.

      Later you can try to find ways to improve performance if this really is required.

      "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • G Offline
        G Offline
        goetz
        wrote on last edited by
        #3

        If you don't need QPushButton's functionalities, got with QLabel.

        For your layout problem:

        @
        QFrame *frame = new QFrame();
        QVBoxLayout *layout = new QVBoxLayout(frame);
        layout->setContentsMargins(0, 0, 0, 0); // or some other value
        QLabel *label = new QLabel(frame);
        label->setText(tr("Do some fancy stuff2));
        layout->addWidget(label);
        frame->setLayout(layout)
        @

        http://www.catb.org/~esr/faqs/smart-questions.html

        1 Reply Last reply
        0
        • Z Offline
          Z Offline
          zveljkovic
          wrote on last edited by
          #4

          It's been late when i posted this so i forgot to tell that i want to layout or other container expand to accommodate label size. i.e. when label has text "a" control width should be ~ 10px & when label has text "alternate" to control resize to ~ 70px (all based on label width without cropping). Definitely i like this method for custom controls to be created via code and now I am trying to find solution for this.

          1 Reply Last reply
          0
          • Z Offline
            Z Offline
            zveljkovic
            wrote on last edited by
            #5

            Just to clarify some more:

            I want to create custom control that will be styled using style sheets. It will contain text and styled according to external style sheets (set on QApp). This control will contain few words at max and it needs to resize it self so the text is always seen + padding & borders set from style sheets. This is first control.

            Second control will just have HorizontalLayout and my custom control will be added to that layout so i can have some styleable status bar.

            Thank you all for help!

            1 Reply Last reply
            0
            • Z Offline
              Z Offline
              zveljkovic
              wrote on last edited by
              #6

              I have some updates. First i was having container issues with my test control. I added directly to QFrame and not to layout. Now when setting Fixed size policy to both QFrame (my control) and QLabel to Fixed/Fixed all looks good (label full size + qframe border). But if i set text to label to some smaller after that, label resizes but QFrame does not so i got QFrame background visible where previously was text.

              constructor (class inherits from QFrame)
              @ _innerFrame = this;
              _innerFrame->setStyleSheet("background-color:Lime; border:3px solid #AAA; border-radius: 5px;");
              _innerFrame->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed);
              _innerFrame->setMinimumWidth(200);
              QVBoxLayout *layout = new QVBoxLayout(_innerFrame);
              layout->setContentsMargins(0, 0, 0, 0); // or some other value
              _label = new QLabel(_innerFrame);
              _label->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed);
              _label->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
              _label->setText("#textasdfasdfasdfasfdasdfasdfasdfasdf");
              _label->setStyleSheet("background-color: Red;");
              layout->addWidget(_label);
              _innerFrame->setLayout(layout);@

              code for setting text in label
              @
              _label->setText(Text);
              this->adjustSize(); //QFrame
              @

              1 Reply Last reply
              0
              • G Offline
                G Offline
                goetz
                wrote on last edited by
                #7

                If you set the size policy of the label to fixed it does not have any chance to enlarge according to the contents...

                http://www.catb.org/~esr/faqs/smart-questions.html

                1 Reply Last reply
                0
                • Z Offline
                  Z Offline
                  zveljkovic
                  wrote on last edited by
                  #8

                  I solved it finnaly. Thanks Volker i figured that in the process. Problem is that multiple layouts "create problems" (just in my head :D). The problem that i was trying to solve is that i wanted to my QFrame and QLabel occupy less space then given by outer layout. Finally i found solution by not giving my custom control additional space by putting QSpacerItem in outer layout that will force my controls to minimum (wanted) size.

                  Thanks for help!

                  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