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. QDoubleSPINBOX text color not changing
Forum Updated to NodeBB v4.3 + New Features

QDoubleSPINBOX text color not changing

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 5.6k 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.
  • L Offline
    L Offline
    Lineaxe
    wrote on last edited by
    #1

    Tried about 20 different ways to try to change the text color in a DoubleSpinBox. it somehow gets created as a SpinBox
    even thought the ui header code shows it being used as a double spin box ... anyhow , so I have to pass in a regular spinbox object to the function. But no matter what I try , I can't change the text color ... Here is some code modified from an example that is supposed to work with a regular spinbox ... Any ideas ? I know I sure ran out of them...

    void main::memberfunction(QSpinBox *inpBox) {
    QPalette *p = new QPalette();
    p->setColor(QPalette::Text, QColor(161, 161, 161));
    inpBox->setPalette(*p);

    // inpBox.update(); ????????????
    }

    1 Reply Last reply
    0
    • L Offline
      L Offline
      Lineaxe
      wrote on last edited by
      #2

      Uhhh, too many long nights of programming. I did forget that I had to spinboxes as well as 2 doublespin boxes. OMG me head is spinning already......

      1 Reply Last reply
      0
      • L Offline
        L Offline
        Lineaxe
        wrote on last edited by
        #3

        Hmm, even after changing the function over to accepting the DoubleSpin boxes , it still won't change text color. Updating the spinbox was just desperation :)

        void MainWindow::memberfunction(QDoubleSpinBox *inpBox)
        {
        QPalette *p = new QPalette();
        p->setColor(QPalette::Text, QColor(161, 161, 161));
        inpBox->setPalette(*p);
        inpBox->update();

        }

        1 Reply Last reply
        0
        • Chris KawaC Offline
          Chris KawaC Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by Chris Kawa
          #4

          That code is leaking memory(palette instance). Data struct types like QPalette should always be created on the stack.

          As for the question - how a widget looks is style dependent. Some styles might not use certain palette colors for certain elements at all. Even if you manage to set a palette the way you want on your computer it's not gonna look the same everywhere. Also, if a user changes style at runtime, your widget won't update properly, as you override the default palette.

          Changing palettes for a widget is usually not a good idea. If you want to force a specific color on the widget you can use stylesheet:

          inpBox->setStyleSheet("color: rgb(161,161,161); ");
          

          Note though, that setting some style attributes might disable the native styling for the widget, for example setting a border color will most definitely do that.

          1 Reply Last reply
          0
          • L Offline
            L Offline
            Lineaxe
            wrote on last edited by
            #5

            You are right about the memory leak . I had earlier coded it so that it would not need a pointer or the new operator..this particular code should have to delete qpalette to free up resources :) Now I had tried code similar to that for setting stylesheet ,but had used ::Text in the parameters ,like I had seen in an example online. Seems the stylesheet was even easier to set than I had thought !!! Thanks , where do I click to make this issue solved ?

            1 Reply Last reply
            0
            • Chris KawaC Offline
              Chris KawaC Offline
              Chris Kawa
              Lifetime Qt Champion
              wrote on last edited by
              #6

              where do I click to make this issue solved ?

              There's a "Mark as solved" option in the "Topic Tools" button menu.

              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