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. Using QStylesheet in Custom Style -> wrong palette.

Using QStylesheet in Custom Style -> wrong palette.

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

    Hello all,

    I use Qt4.8.4 to build an desktop application. I want to use QStyleSheet to apply a custom look and feel to my application. However I also need to draw custom ui elements in a MyStyle (which inherits from QWindowsVistaStyle). I want to style them with the values from my QStyleSheet.

    What works:
    I set the QStyleSheet to my QApplication, it gets correctly applied on my QWidgets as long as I paint default elements through MyStyle.
    But requesting the palette and painting i.e. a rectangle by my self I still get the default style configuration.

    QStyleSheet
    @
    QWidget {
    background: #e18918;
    }
    @

    Some draw.
    @
    void MyStyle::drawPrimitive(QStyle::PrimitiveElement element, const QStyleOption *opt,
    QPainter *p, const QWidget *w) const
    {
    QWindowsVistaStyle::drawPrimitive(element,opt,p,w);

    qDebug() << opt->palette.background().color;
    

    }
    @

    Painting the item with the default element provides me the correct orange color, however the background color in opt is still default gray.

    How can I read / get the correct value from the QStyleSheet?

    Thanks,

    Jeremias

    1 Reply Last reply
    0
    • J Offline
      J Offline
      jerebo
      wrote on last edited by
      #2

      Ok,

      i checked some code... it looks like that you can not use CSS Styles within custom widgets...

      @ if (QStyleSheetStyle* cssStyle = qobject_cast<QStyleSheetStyle*>(style)) {

              cssStyle->styleSheetPalette(this, &opt, &opt.palette);
      
          }
      

      @

      seems to be the magic, but QStyleSheetStyle is only private, is there any public interface?

      Best,

      Jeremias

      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