Problem with SpinBoxes delegate and TableWidgets

  • Hi, I wonder if somebody know why, when I call the function :


    on my QTableWidget which contains a QSpinBox delegate, exactly the same as this example : SpinBox delegate example from Qt IO

    the SpinBoxes are always hightlighted/selected.... (in light blue since I use Windows)

    I wonder if there is any way I could change this behavior... In fact, it seems like it is the QLineEdit that is selected in the spinbox and the not the spinbox itself.... I tried to deselect()it after the call for the openPersistentEditor but no luck...

    Is there a trick with the QStylesheet (I already tried a couple thing with the Spinboxes, but again, no luck with that).... or maybe there's something I could do with the repaint of the widget... I really don't know at that point...

    Thank you all for any help !

  • Lifetime Qt Champion


    What version of Qt are you using ?
    On what OS ?

  • @SGaist I'm currently using Qt Creator 4.2.1 on Windows 10, and the project is made with Qt 5.7.1MSVC2015_64bit (and will be use only on Windows machine)

  • Qt Champions 2017

    I dont have windows to test on, but is that not normal for edit?
    Just the focus color.
    If it should not have focus, when should it do then ?

  • @mrjj I guess this is the normal behavior... but I also created some QTimeEdit and QComboBoxes delegate and they don't seems to be selected on focus as compared to the QSpinboxes... that's why I'm a bit confused... but it doesn't really matters if it get "on focus/selected", as long as I can programmatically deselect them after... which I didn't find any solution for .

  • Qt Champions 2017


    in the delegate, try call setFocus() on something else after creating the spinedit.
    or try the clearFocus() call.

  • @mrjj Just try both, it doesn't work (tried clearFocus() on the spinbox after is creation, and tried the setFocus() on another widget (a QPushbutton outside the QTableWidget) and even both at the "same time" but still no luck :(

  • Even tried this in the delegate...


  • Qt Champions 2017


    Ok, so focus is sat either multiple times or after the statement.
    I assume the Spin Box Delegate Example is a good test case as it does the same ?

  • @mrjj It's call'd after since I tried to change the selection in a slot called by valueChanged(double) of the QDoubleSpinbox but the selection is made after this signal is called...

  • Qt Champions 2017


    ok a bit odd then.
    if u make a spinedit your self and test with. it does same ?

  • Seems like it.... It come from the openPersistentEditor.... anyways, for now, I think I'll just change the default QStyleSheet at the creation of the Spinbox, and then change it back when the widget is accessed !... very weird !...

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.