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 setpalette not working in cellWidget

QLabel setpalette not working in cellWidget

Scheduled Pinned Locked Moved Solved General and Desktop
12 Posts 4 Posters 1.3k Views
  • 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 SGaist

    Hi,

    Please write your question in English as it is the main language of the forum.

    Or use the Hungarian sub-forum if you want to stay in your native language.

    KutyusK Offline
    KutyusK Offline
    Kutyus
    wrote on last edited by
    #3

    @SGaist Sorry, my mistake, I inserted a bad clipboard.

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

      Why are you using a QLabel as cell widget ?

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

      KutyusK 1 Reply Last reply
      1
      • SGaistS SGaist

        Why are you using a QLabel as cell widget ?

        KutyusK Offline
        KutyusK Offline
        Kutyus
        wrote on last edited by
        #5

        @SGaist
        I monitor bluetooth LE devices with qtablewidget. Would I put the device icon in the cell and the background would be green or red, depending on whether it is connected?

        mrjjM Christian EhrlicherC 2 Replies Last reply
        0
        • KutyusK Kutyus

          @SGaist
          I monitor bluetooth LE devices with qtablewidget. Would I put the device icon in the cell and the background would be green or red, depending on whether it is connected?

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

          @Kutyus
          Hi
          but TableWidget already supports other colors for the background ?

          alt text

          So cant you just use that ?

          Or did i miss something ? :)

          You do it via the items.

          QBrush brush1(QColor(0, 255, 127, 255));
          brush1.setStyle(Qt::SolidPattern);
          QTableWidgetItem *item = new QTableWidgetItem(); ( or take existing )
          item->setBackground(brush1);

          KutyusK 1 Reply Last reply
          1
          • mrjjM mrjj

            @Kutyus
            Hi
            but TableWidget already supports other colors for the background ?

            alt text

            So cant you just use that ?

            Or did i miss something ? :)

            You do it via the items.

            QBrush brush1(QColor(0, 255, 127, 255));
            brush1.setStyle(Qt::SolidPattern);
            QTableWidgetItem *item = new QTableWidgetItem(); ( or take existing )
            item->setBackground(brush1);

            KutyusK Offline
            KutyusK Offline
            Kutyus
            wrote on last edited by Kutyus
            #7

            @mrjj
            The Tablewidgetitem setbackground works, but I don't have a tablewidgetitem, I have a cellwidget, I can't color the background.

            mrjjM 1 Reply Last reply
            0
            • KutyusK Kutyus

              @SGaist
              I monitor bluetooth LE devices with qtablewidget. Would I put the device icon in the cell and the background would be green or red, depending on whether it is connected?

              Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #8

              @Kutyus said in QLabel setpalette not working in cellWidget:

              Would I put the device icon in the cell and the background would be green or red, depending on whether it is connected?

              Don't use a cell widget but simply use what QTableWidgetItem has - it's enough for your use case (text, an icon and setting the (background) color)

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              1 Reply Last reply
              2
              • KutyusK Kutyus

                @mrjj
                The Tablewidgetitem setbackground works, but I don't have a tablewidgetitem, I have a cellwidget, I can't color the background.

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

                @Kutyus
                But do you need that cell widget ?
                I mean the item can have icon and color but maybe you also show
                other stuff not easy to make with item alone ?

                KutyusK 1 Reply Last reply
                0
                • mrjjM mrjj

                  @Kutyus
                  But do you need that cell widget ?
                  I mean the item can have icon and color but maybe you also show
                  other stuff not easy to make with item alone ?

                  KutyusK Offline
                  KutyusK Offline
                  Kutyus
                  wrote on last edited by
                  #10

                  @mrjj said in QLabel setpalette not working in cellWidget:

                  But do you need that cell widget ?
                  I mean the item can have icon and color but maybe you also show
                  other stuff not easy to make with item alone ?

                  I tried this solution because I couldn't find how to center the icon.

                  mrjjM 1 Reply Last reply
                  0
                  • KutyusK Kutyus

                    @mrjj said in QLabel setpalette not working in cellWidget:

                    But do you need that cell widget ?
                    I mean the item can have icon and color but maybe you also show
                    other stuff not easy to make with item alone ?

                    I tried this solution because I couldn't find how to center the icon.

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

                    @Kutyus
                    Hi
                    Ok, well centering the icon is not supported out of the box
                    and you would need to use a Delegate for that with custom painting.
                    https://forum.qt.io/topic/83265/centering-decorationrole-icon-in-qtableview-cell/9

                    Anyway, if the palette is not working you can use a stylesheet to set labels color.

                    alt text

                    KutyusK 1 Reply Last reply
                    0
                    • mrjjM mrjj

                      @Kutyus
                      Hi
                      Ok, well centering the icon is not supported out of the box
                      and you would need to use a Delegate for that with custom painting.
                      https://forum.qt.io/topic/83265/centering-decorationrole-icon-in-qtableview-cell/9

                      Anyway, if the palette is not working you can use a stylesheet to set labels color.

                      alt text

                      KutyusK Offline
                      KutyusK Offline
                      Kutyus
                      wrote on last edited by
                      #12

                      @mrjj
                      Thanks for the tip, and with this we managed to solve it:
                      https://stackoverflow.com/questions/32216568/how-to-set-icon-center-in-qtableview

                      1 Reply Last reply
                      1

                      • Login

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