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. How to use QGraphicsScene::setStyle()?
Forum Updated to NodeBB v4.3 + New Features

How to use QGraphicsScene::setStyle()?

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

    Hi everyone,
    I am using QGraphicsProxyWidget to embed QWidgets inside a QGraphicsScene. The problem comes with the style with which this widgets are drawed. From the documentation :

    A top-level item's style defaults to QGraphicsScene::style. A top-level widget's style defaults to QApplication::style
    So, I have to set the style to QGraphicsScene. Right now, I am using QWidget::setStyleSheet to set custom styles based on CSS (QSS).

    My question is: how can I use QGraphicsScene::setStyle, which requires an instance of QStyle, since I haven't got one? Can somebody post an example using it and setting an stylesheet-enabled style?

    I have tried already QStyleFactory::create, but there is no way to create an instance of QStyleSheetStyle.

    Thank you very much,
    Best regards,
    LoPiTaL

    raven-worxR 1 Reply Last reply
    0
    • L LoPiTaL

      Hi everyone,
      I am using QGraphicsProxyWidget to embed QWidgets inside a QGraphicsScene. The problem comes with the style with which this widgets are drawed. From the documentation :

      A top-level item's style defaults to QGraphicsScene::style. A top-level widget's style defaults to QApplication::style
      So, I have to set the style to QGraphicsScene. Right now, I am using QWidget::setStyleSheet to set custom styles based on CSS (QSS).

      My question is: how can I use QGraphicsScene::setStyle, which requires an instance of QStyle, since I haven't got one? Can somebody post an example using it and setting an stylesheet-enabled style?

      I have tried already QStyleFactory::create, but there is no way to create an instance of QStyleSheetStyle.

      Thank you very much,
      Best regards,
      LoPiTaL

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by raven-worx
      #2

      @LoPiTaL
      Since you are using QGraphicsProxyWidget you actually should set your stylesheet to your QApplication instance - using QApplication::setStylesheet()
      This is because widgets set to a QGraphicsProxyWidget are not allowed to have a parent set -> top level widget.
      Or - if not possible otherwise - to every widget itself.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

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

        Yes, ultimately I have used QWidget::setStyleSheet() to every widget inside the QGraphicsScene. I couldn't use QApplication::setStylesheet() because I have two sets of styles: the main interface style (which is applied to QApplication) and the user objects style, which was the one I wanted to use in QGraphicsScene.

        I was hoping that there would be an easier solution by means of QGraphicsScene::setStyle(), but seems to not be possible.

        raven-worxR 1 Reply Last reply
        0
        • L LoPiTaL

          Yes, ultimately I have used QWidget::setStyleSheet() to every widget inside the QGraphicsScene. I couldn't use QApplication::setStylesheet() because I have two sets of styles: the main interface style (which is applied to QApplication) and the user objects style, which was the one I wanted to use in QGraphicsScene.

          I was hoping that there would be an easier solution by means of QGraphicsScene::setStyle(), but seems to not be possible.

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          @LoPiTaL
          you could still combine both styles in one CSS. You just need to adapt your selectors.
          E.g. you could set an property to your widgets and only apply certain styles to them.

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          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