Results 1 to 3 of 3

Thread: How to change LineEdits and ComboBx focus style

  1. #1
    Join Date
    Dec 2014
    Posts
    82
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default How to change LineEdits and ComboBx focus style

    Hi,

    I'm making a gui app with Qt 4.8.5. I have a basic wizard with 3 wizardpages. On the fisrt one I have a combobox (mycb) and two lineedits (le1 and le2).

    The thing is that when the have the focus they have a thin light blue border which I would like to change and make it bigger or to have another color so the user can see which element has the focus clearly.

    I've tried to do it first with the combobox, implementing a BaseComboBox (class BaseComboBox : public QComboBox) class with that:

    Qt Code:
    1. void BaseComboBox::focusInEvent(QFocusEvent *e)
    2. {
    3. if (e->reason() == Qt::TabFocusReason)
    4. {
    5. emit(changeStyle());
    6. }
    7. QComboBox::focusInEvent(e);
    8. }
    To copy to clipboard, switch view to plain text mode 

    and then in the wizard page constructor:
    Qt Code:
    1. connect(mycb,SIGNAL(changeStyle()),this, SLOT(changeStyleSLOT())); // BaseComboBox mycb;
    To copy to clipboard, switch view to plain text mode 

    and the slot:
    Qt Code:
    1. void WPConfigs12::changeStyleSLOT()
    2. {
    3. mycb->setStyleSheet("BaseComboBox:focus { border: 5px solid red;");
    4. }
    To copy to clipboard, switch view to plain text mode 

    But it doesn't change. It just works as always with the thin blue default border. Any idea for that?


    Thank you so much!

  2. #2
    Join Date
    May 2012
    Posts
    136
    Thanks
    2
    Thanked 27 Times in 24 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to change LineEdits and ComboBx focus style

    You don't have to apply the stylesheet when the focus is happening, you can just set it at the start of the program for the form

    myComboBoxContainingForm->setStyleSheet(QComboBox:focus{ border: 5px solid red; });
    now all QComboBoxes will get a red 5px border when they are focused

  3. The following user says thank you to StrikeByte for this useful post:

    roseicollis (26th February 2015)

  4. #3
    Join Date
    Dec 2014
    Posts
    82
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to change LineEdits and ComboBx focus style

    You are right StrikeByte... I just made a mess with the stylesheets so once I fixed it what you said worked fine. Thank you so much! So simple and I wasn't able to see it hehe

Similar Threads

  1. Replies: 3
    Last Post: 1st October 2014, 05:29
  2. [Qt 4.6.3 Linux] style sheet focus on QPushButton
    By snooker9 in forum Qt Programming
    Replies: 0
    Last Post: 5th March 2012, 13:27
  3. Change key focus
    By sajis997 in forum Qt Programming
    Replies: 1
    Last Post: 15th November 2011, 04:38
  4. QComboBox - style sheet set text color non focus?
    By alan in forum Qt Programming
    Replies: 0
    Last Post: 12th March 2011, 23:31

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.