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. Combine multiple Objects to one
Forum Updated to NodeBB v4.3 + New Features

Combine multiple Objects to one

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 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.
  • B Offline
    B Offline
    Beatsteak
    wrote on 8 Sept 2016, 07:54 last edited by
    #1

    Hey,

    is it possible to combine multiple objects to one? I have 5 QFrame line objects. Now I want them to change color on hovering. As far as I know, the best way to do this is to edit the style sheet of an object with

    #line::hover {
    border: 5px solid black;
    }
    

    Now I want to change the color of all my lines if I hover one of them. So can I combine the line objects to one object and give them one style sheet so that all of them change their color if I hover one?

    Thanks!

    R 1 Reply Last reply 8 Sept 2016, 08:01
    0
    • B Beatsteak
      8 Sept 2016, 07:54

      Hey,

      is it possible to combine multiple objects to one? I have 5 QFrame line objects. Now I want them to change color on hovering. As far as I know, the best way to do this is to edit the style sheet of an object with

      #line::hover {
      border: 5px solid black;
      }
      

      Now I want to change the color of all my lines if I hover one of them. So can I combine the line objects to one object and give them one style sheet so that all of them change their color if I hover one?

      Thanks!

      R Offline
      R Offline
      raven-worx
      Moderators
      wrote on 8 Sept 2016, 08:01 last edited by raven-worx 9 Aug 2016, 08:23
      #2

      @Beatsteak said in Combine multiple Objects to one:

      Now I want to change the color of all my lines if I hover one of them. So can I combine the line objects to one object and give them one style sheet so that all of them change their color if I hover one?

      This should give you an idea:

      #line[MyHoveredProperty="true"] {
      border: 5px solid black;
      }
      
      void RepolishWidget( QWidget* widget )
      {
              widget->style()->unpolish(widget );
              widget->style()->polish(widget );
              QEvent event(QEvent::StyleChange);
              QApplication::sendEvent(widget, &event);
              widget->update();
              widget->updateGeometry();
      }
      ...
      bool hovered;
      foreach( QFrame* frame, frames )
      {
           frame->setProperty("MyHoveredProperty", hovered);
           frame->style()->polish(frame); // in case the content margins (border-width, padding, margin) changes with your CSS you need to call RepolishWidget() instead, otherwise this is enough
      }
      

      --- 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
      2
      • B Offline
        B Offline
        Beatsteak
        wrote on 8 Sept 2016, 08:58 last edited by
        #3

        Thanks for your answer, this sounds like what I was looking for. But where do I have to put this code? The putter part seems to belong into the style sheet? And where do I put the rest of your code?

        R 1 Reply Last reply 8 Sept 2016, 09:04
        0
        • B Beatsteak
          8 Sept 2016, 08:58

          Thanks for your answer, this sounds like what I was looking for. But where do I have to put this code? The putter part seems to belong into the style sheet? And where do I put the rest of your code?

          R Offline
          R Offline
          raven-worx
          Moderators
          wrote on 8 Sept 2016, 09:04 last edited by
          #4

          @Beatsteak said in Combine multiple Objects to one:

          And where do I put the rest of your code?

          depends on how your code looks like.

          For example you can install an event filter on your frame widgets and listen for a QEvent::Enter / QEvent::Leave event types and set the property of all your frames.

          Or you subclass QFrame and override the enterEvent() / leaveEvent() handlers there and emit a signal. Then in a connected slot set the properties of all frames.

          Putting your frame widgets into a list (like in my example) lets you quickly traverse them with a minimum amount of code.

          --- 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
          1

          1/4

          8 Sept 2016, 07:54

          • Login

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