Results 1 to 8 of 8

Thread: Multiple setAttribute()

  1. #1
    Join Date
    Mar 2013
    Posts
    34
    Thanks
    1

    Default Multiple setAttribute()

    Is it possible to set an attribute for all the widgets at once or do I have to call setAttribute() on each of the instance?

    For example, is it possible to set Qt::WA_MacShowFocusRect for all QLineEdit (for already created and also for yet to be created instances) or do I have to manually set the attribute on each lineEdit?

  2. #2
    Join Date
    Sep 2012
    Location
    Iran, Tehran
    Posts
    76
    Thanks
    17
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Multiple setAttribute()

    If all of them have the same parent, you can use QObject::findChildren then loop through the list and call setAttribute() on each child.

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Multiple setAttribute()

    You could consider creating a QProxyStyle subclass and implement polish(QWidget*) such that it applies that attribute to all QLineEdit instances it gets

    Cheers,
    _

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Multiple setAttribute()

    Subclass QLineEdit, put a setAttribute() call in the constructor, and use that class instead of QLineEdit when you create your widgets. You can catch line edits created in item views using QItemEditorFactory. If you don't create them with the wrong properties then you don't need to try to retrospectively fix them.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Multiple setAttribute()

    I'd go for Kevin's solution. It seems universal. What Chris suggests requires intervention for each and every line edit created and there is no control over those that come from some external code. polish() on the other hand will catch those too.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Mar 2013
    Posts
    34
    Thanks
    1

    Default Re: Multiple setAttribute()

    Thank you all for the suggestion, I'll try to go with polish() then.

  7. #7
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Multiple setAttribute()

    There are some caveats in the QProxyStyle docs if you intend doing something similar for other types of control or are using a non-Qt supplied style.

  8. #8
    Join Date
    Mar 2013
    Posts
    34
    Thanks
    1

    Default Re: Multiple setAttribute()

    Thanks for the heads-up, I think I'll use only QLineEdit for now...

Similar Threads

  1. QDomElement::setAttribute() doesn't work : (
    By Qiieha in forum Qt Programming
    Replies: 2
    Last Post: 11th August 2011, 14:21
  2. QWebElement setAttribute not working as expected
    By pherthyl in forum Qt Programming
    Replies: 2
    Last Post: 12th April 2011, 07:17
  3. Replies: 1
    Last Post: 16th September 2010, 15:57
  4. Replies: 0
    Last Post: 21st May 2007, 22:38
  5. Replies: 0
    Last Post: 21st December 2006, 11:48

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.