[Qt-interest] Multiple Objects all having the Same name
Michael Jackson
imikejackson at gmail.com
Tue Feb 14 21:50:34 CET 2012
On Feb 14, 2012, at 3:41 PM, Eduardo Robles Elvira wrote:
> On Tue, Feb 14, 2012 at 9:30 PM, Michael Jackson <imikejackson at gmail.com> wrote:
>> Is it a "Bad Idea" to have multiple objects all have the same Object Name? I am writing some code and trying to solve a problem where the easiest solution would be to have some of my GUI widgets all have the same Object Name. But I am thinking this is a "really bad" idea.
>>
>> Feedback/thoughts would be great.
>>
>> Thanks
>
> Hi Michael:
>
> I don't know exactly why would this be a really bad idea. Anyway,
> whats the problem whose easiest solution is having all the objects
> have the same name? I'm going out here on a limp, but if what you want
> is to apply the same qss (qt style sheets) to many widgets, you can
> add a dynamic property to the given widgets and then use that as a
> selector in the style sheets, i.e.:
>
> fooWidget->setProperty("class", "darkWidget");
> ....
> barWidget->setProperty("class", "darkWidget");
>
> And then in the style sheet file:
>
> *[class="darkWidget"] {
> // apply your style here
> }
>
> Regards,
> --
> Eduardo Robles Elvira edulix at wadobo.com
> +34 668 824 393 skype: edulix2
> Wadobo Desarrolladores de Sistemas S.L.L. http://www.wadobo.com
> it's not magic, it's wadobo!
Actually I am using the object name as the name of a property in another class in order to use the "setProperty()" methods to set that particular property. I can get the name of the object who signaled the current method (which is a slot itself). Based on that name I know what property to set. This is straight forward with things like spin boxes and check boxes. The current layout for an "Input File" has both a QLineEdit and a QPushButton. Either can set the property. The QPushButton through a File Open dialog and the QLineEdit through a raw path specification. The Guis are dynamically created otherwise this would be much simpler. And things like "findChild" uses the object name. I'll have to rethink my design as this seems like an edge case where the outcome is undefined.
THanks for the quick feedback everyone.
Mike Jackson
More information about the Qt-interest-old
mailing list