[Solved]Help with QCombobox Popup resizing



  • Hello,

    i have several editable QComboBoxes in a row of a QGridLayout. I want to stretch the QComboBox which has focus.
    @
    class CComboBox : public QComboBox {
    Q_OBJECT
    public:
    CComboBox(QWidget* parent = 0);
    signals:
    void focusIn();
    void focusOut();
    protected:
    void focusInEvent(QFocusEvent* e);
    void focusOutEvent(QFocusEvent* e);
    };

    CComboBox::CComboBox(QWidget* parent)
    : QComboBox(parent) {
    }

    void CComboBox::focusInEvent(QFocusEvent* e) {
    emit focusIn();
    QComboBox::focusInEvent(e);
    }

    void CComboBox::focusOutEvent(QFocusEvent* e) {
    emit focusOut();
    QComboBox::focusOutEvent(e);
    }
    @

    And I'm connecting it to this slot:

    @
    void CEditor::focusIn() {
    for (int i = 0; i < m_layout->columnCount(); ++i) {
    if (m_layout->itemAtPosition(1, i)->widget() == QObject::sender()) {
    m_layout->setColumnStretch(i, 1000);
    }else{
    m_layout->setColumnStretch(i, 1);
    }
    }
    }

    @

    This works perfectly if I click on any of the editors or tab to them. However if I click the popup button then the popupview gets opened before the combobox gets resized. If i close and reopen the popupview then it has the right location/size.

    I tried to manually move/resize the view since focusoutevent is called after clicking the popup button and "width()" function gives me the correct width:
    @
    void CComboBox::focusOutEvent(QFocusEvent *e) {
    view()->setGeometry(
    0,
    0,
    width(),
    view()->height()
    );
    emit focusOut();
    QComboBox::focusOutEvent(e);
    }
    @

    However even though it gets resized, popupview is still clipped to the wrong size.

    1.) Any ideas how to remedy this?
    2.) Also any ideas on how to prevent emiting focusOut() when the popupview gets selected?

    My english is not so good, hope i have declared my problems well enogh to understand.

    Thx, in advance



  • Try to reimplement enterEvent() or mousePressEvent(). Not sure if they will work though. enterEvent should be called whenever the mouse is over the widget (not sure if this is what you are looking for)



  • Thx,
    its a workaroung i can live with :))))



  • another thing you could do if you do not wish to resize the CBox at each mouseOver is to reimplement showPopup and hidePopup methods :)



  • Thx, will try it.


Log in to reply
 

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