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. Style for custom QWidget
Forum Updated to NodeBB v4.3 + New Features

Style for custom QWidget

Scheduled Pinned Locked Moved General and Desktop
23 Posts 2 Posters 8.3k 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #10

    Just to be sure, with only this code it doesn't work ? What are your other style sheets ?

    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 Offline
      S Offline
      sting
      wrote on last edited by
      #11

      With this code it doesn't work for QWidget and it does for QGroupBox. The other stylesheets I use that work are for QGroupBox. For QGroupBox I use the border section and the QGroupBox::title selector.

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

        This code is working fine here. Can you post all your style sheets ?

        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 Offline
          S Offline
          sting
          wrote on last edited by
          #13

          I have changed everything to use QGroupBox temporarily and it seems to work. I wonder if it is a problem with my environment. I am using ubunto linux as a host. It supprised me that that simple of an application caused the issue to show.

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

            Does it also happen if you set this style sheet on a default project ? Just create a new one using a QDialog as base class and set the style sheet on it

            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 Offline
              S Offline
              sting
              wrote on last edited by
              #15

              I made the dialog example and I think I found the following:

              If I use a plain QWidget the stylesheets work fine.

              If I use a custom widget that inherits from QWidget the style sheets do not work.

              If I use a custom widget that inherits from QGroupBox it does work. Just the same as my other example.

              @
              Dialog::Dialog(QWidget *parent)
              : QDialog(parent) {
              QVBoxLayout *mainLayout = new QVBoxLayout;
              setLayout(mainLayout);
              //QWidget *widget = new QWidget(this);
              //QGroupBox *widget = new QGroupBox(this);
              ToneWidget *widget = new ToneWidget(this);
              widget->setFixedWidth(100);
              widget->setFixedHeight(100);
              //widget->setObjectName("Foo");
              //widget->setStyleSheet("QWidget#Foo {border: 2px solid red; border-radius: 2px}");
              //widget->setStyleSheet("QGroupBox#Foo {border: 2px solid red; border-radius: 2px}");
              // Try to set it externally
              //widget->setStyleSheet("ToneWidget#Foo {border: 2px solid red; border-radius: 2px}");
              mainLayout->addWidget(widget);
              }
              @

              @
              class ToneWidget : public QWidget
              //class ToneWidget : public QGroupBox
              {
              Q_OBJECT
              public:
              ToneWidget(QWidget* parent = 0);
              };
              @

              @
              ToneWidget::ToneWidget(QWidget* parent) : QWidget(parent)
              //ToneWidget::ToneWidget(QWidget* parent) : QGroupBox(parent)
              {
              setFixedWidth(100);
              setFixedHeight(100);

              setObjectName("bar");
              setStyleSheet("QWidget#bar {border: 2px solid red; border-radius: 2px}");
              //setStyleSheet("QGroupBox#bar {border: 2px solid red; border-radius: 2px}");
              //setStyleSheet("ToneWidget#bar {border: 2px solid red; border-radius: 2px}");
              

              }
              @

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

                Which OS are you running on ? I can't make it fail here

                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 Offline
                  S Offline
                  sting
                  wrote on last edited by
                  #17

                  I am using ubuntu the latest 64 bit version. 14.3 or 14.4 I will check again when I get home.

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    sting
                    wrote on last edited by
                    #18

                    I will take it to work tomorrow and try it on a windows machine. I will be depressed if it works on windows and not on linux.

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      sting
                      wrote on last edited by
                      #19

                      "From the Qt 5 documentation"http://qt-project.org/doc/qt-5/stylesheet-reference.html

                      QWidget Supports only the background, background-clip and background-origin properties.

                      I should have read this a long time ago. Sorry to waste your time.

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

                        Which one were you trying to use ?

                        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 Offline
                          S Offline
                          sting
                          wrote on last edited by
                          #21
                          setStyleSheet("QWidget {border: 2px solid red; border-radius: 2px}");
                          
                          1 Reply Last reply
                          0
                          • SGaistS Offline
                            SGaistS Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on last edited by
                            #22

                            This one should be working

                            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 Offline
                              S Offline
                              sting
                              wrote on last edited by
                              #23

                              I just did the same experiment on a Windows machine with Qt Creator 3.1.2
                              Based on Qt 5.3.1 (MSVC 2010, 32 bit) with the same device. If I take any QWidget and apply the above stylesheet and it doesn't work. If I change the QWidget to a QGroupBox with the appropriate change in the stylesheet the border does show.

                              I have just changed all of the QWidgets that I need a border around to QGroupBox for now. Should I mark this thread closed?

                              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