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. QTimeedit set color
Qt 6.11 is out! See what's new in the release blog

QTimeedit set color

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 1.1k Views 2 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.
  • S Offline
    S Offline
    SurendarK
    wrote on last edited by
    #1

    Hi,

    I want to set the font color for QTimeedit in source code(mainwindow.cpp) . Instead of setstylesheet function, is there any tool to set the font color in qtimeedit?. I tried QPalette class,but it was not work.
    Can you help me to sort out this issues?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mostefa
      wrote on last edited by mostefa
      #2

      Hi @SurendarK

      QPalette *palette = new QPalette();
      palette->setColor(QPalette::Text,Qt::red);//Here i change font color to red
      yourtimeedit->setPalette(*palette);
      

      Hope this can help!

      1 Reply Last reply
      2
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi
        Small note.

        There is no reason to new the palette

        QPalette palette;
        ...
        yourtimeedit->setPalette(palette);

        Works just fine

        The setPalette makes copy.

        Also, with new you must then
        delete palette;
        to avoid to leak.

        M 1 Reply Last reply
        2
        • mrjjM mrjj

          Hi
          Small note.

          There is no reason to new the palette

          QPalette palette;
          ...
          yourtimeedit->setPalette(palette);

          Works just fine

          The setPalette makes copy.

          Also, with new you must then
          delete palette;
          to avoid to leak.

          M Offline
          M Offline
          mostefa
          wrote on last edited by
          #4

          @mrjj said in QTimeedit set color:

          Hi
          Small note.

          There is no reason to new the palette

          QPalette palette;
          ...
          yourtimeedit->setPalette(palette);

          Works just fine

          The setPalette makes copy.

          Also, with new you must then
          delete palette;
          to avoid to leak.

          Good point @mrjj ,

          Delete palette was obvious for me , but you are right ,

          QPalette palette;
          

          Already does the job,

          Thank you for your answer !

          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