Results 1 to 4 of 4

Thread: how to change the spinbox background color when user edit

  1. #1
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default how to change the spinbox background color when user edit

    hi friends,
    I just want to know how i can change the background color of a qspinbox when the user click on the spinbox to edit it and once user completes editing i have to revert back to old background state.

    proper way is to use signals of valueChange and editFinished or touse stylesheet ..?
    im n0t able to find any stylesheet for edit in qspinbox

    please help me .
    "Behind every great fortune lies a crime" - Balzac

  2. #2
    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: how to change the spinbox background color when user edit

    Quote Originally Posted by wagmare View Post
    proper way is to use signals of valueChange and editFinished or touse stylesheet ..?
    This is not an "or" question.

    You need two things:
    1) a way to detect user editing and finish editing, most likely through signals
    2) a way to modify the widget's appearance when necessary. That can be done through a style sheet or by manipulating the widget's palette.

    Quote Originally Posted by wagmare View Post
    im n0t able to find any stylesheet for edit in qspinbox
    All widgets can have a stylesheet applied, so that property is documented in QWidget

    Cheers,
    _

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

    atenakid (20th February 2014)

  4. #3
    Join Date
    Jan 2014
    Location
    Korea
    Posts
    7
    Thanks
    6
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: how to change the spinbox background color when user edit

    Quote Originally Posted by anda_skoa View Post
    This is not an "or" question.

    You need two things:
    1) a way to detect user editing and finish editing, most likely through signals
    2) a way to modify the widget's appearance when necessary. That can be done through a style sheet or by manipulating the widget's palette.


    All widgets can have a stylesheet applied, so that property is documented in QWidget

    Cheers,
    _
    Hi, i got the same problem. My dialog contains several QspinBox, and it does not highlight which one has been changed like in QComboBox.
    One solution would be using signal and slot like

    connect(qspinBox, SINGAL(currentIndexChanged(int)), this, SLOT( changeQspinBackground());
    Then, Do i have to implement changeQSpinBackground for every Qspinbox?
    However, I use many QSpinbox, how can I do this in more effective way?

    Thanks you,

  5. #4
    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: how to change the spinbox background color when user edit

    You can get the sender of a signal using QObject::sender()

    Qt Code:
    1. void SomeClass::someSlot()
    2. {
    3. QSpinBox *spinBox = qobject_cast<QSpinBox*>(sender());
    4. if (!spinBox)
    5. return;
    6.  
    7. // do something with spinBox
    8. }
    To copy to clipboard, switch view to plain text mode 

    Alternatively use a QSignalMapper

    Cheers,
    _

Similar Threads

  1. cannot change QStatusBar background color
    By cic in forum Qt Programming
    Replies: 1
    Last Post: 18th November 2013, 16:21
  2. cannot change QLCDNumber background color
    By saman_artorious in forum Qt Programming
    Replies: 2
    Last Post: 13th March 2013, 16:04
  3. how to change value of spinbox by user interface?
    By kinjalp in forum Qt Programming
    Replies: 1
    Last Post: 1st February 2012, 13:25
  4. Replies: 1
    Last Post: 17th August 2010, 16:17
  5. Slot to color background of line edit on textedited
    By tpf80 in forum Qt Programming
    Replies: 5
    Last Post: 21st June 2007, 09:02

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.