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. Proprietary stylesheet for a button in external stylesheet file
Forum Updated to NodeBB v4.3 + New Features

Proprietary stylesheet for a button in external stylesheet file

Scheduled Pinned Locked Moved General and Desktop
7 Posts 2 Posters 3.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.
  • A Offline
    A Offline
    absfrm
    wrote on last edited by
    #1

    Hi
    I'm loading an external style sheet file for my form.
    this is code :
    @
    QPushButton{
    background: transparent;
    color: white;
    }

    QPushButton QPushButton:on{
    background: transparent;
    color: white;
    }
    @

    How can i set this style sheet for just one button with name btngo ?

    If You Want You Can!

    1 Reply Last reply
    0
    • D Offline
      D Offline
      DerManu
      wrote on last edited by
      #2

      Try
      @
      qApp->findChild<QPushButton*>("btngo")->setStyleSheet("...style...");
      @

      If you have multiple "btngo"-buttons that should all have that stylesheet, use findChildren and iterate over the list.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        absfrm
        wrote on last edited by
        #3

        @
        qApp->findChild<QPushButton*>("btngo")->setStyleSheet("QPushButton{background: transparent; color: white;}QPushButton QPushButton:pressed{background: transparent;color: white;}");
        @
        no work!

        any way to explain it in style sheet file?

        If You Want You Can!

        1 Reply Last reply
        0
        • D Offline
          D Offline
          DerManu
          wrote on last edited by
          #4

          Is the correct pointer returned by findChild? Does the styleSheet work when using it on the variable (i.e. ui->btngo->setStyleSheet or similar?

          1 Reply Last reply
          0
          • A Offline
            A Offline
            absfrm
            wrote on last edited by
            #5

            No,i want to define it in .qss file in external style sheet

            ui->btngo->setStyleSheet(); is working right

            If You Want You Can!

            1 Reply Last reply
            0
            • D Offline
              D Offline
              DerManu
              wrote on last edited by
              #6

              So in this case
              @
              qApp->findChild<QPushButton*>("btngo")
              @
              seems to return the wrong button (or none at all). Is the button really called btngo? What's returned by ui->btngo->name()?
              Further, try using the findChild not on qApp but on your main window (or the window which contains the button) instead.

              //EDIT: Ah now I think I get it, you want to define inside the CSS file which button name to style, right? I don't know of a Qt-way to do that. Maybe you should parse the CSS file yourself and add some extended syntax which then uses the findChild function to apply it to a QWidget with the specified name.

              1 Reply Last reply
              0
              • A Offline
                A Offline
                absfrm
                wrote on last edited by
                #7

                [quote author="DerManu" date="1338837244"]So in this case
                //EDIT: Ah now I think I get it, you want to define inside the CSS file which button name to style, right? I don't know of a Qt-way to do that. Maybe you should parse the CSS file yourself and add some extended syntax which then uses the findChild function to apply it to a QWidget with the specified name.[/quote]

                yes right.
                i fixed it with parsing string.
                thanks a lot.

                If You Want You Can!

                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