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

Combine multiple Objects to one

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 1.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.
  • BeatsteakB Offline
    BeatsteakB Offline
    Beatsteak
    wrote on 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!

    raven-worxR 1 Reply Last reply
    0
    • BeatsteakB Beatsteak

      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!

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by raven-worx
      #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
      • BeatsteakB Offline
        BeatsteakB Offline
        Beatsteak
        wrote on 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?

        raven-worxR 1 Reply Last reply
        0
        • BeatsteakB Beatsteak

          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?

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on 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

          • Login

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