Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved]Help with QCombobox Popup resizing
QtWS25 Last Chance

[Solved]Help with QCombobox Popup resizing

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 3.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    udx6bs
    wrote on last edited by
    #1

    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

    Using Qt5.02/32bit on Windows Win7/64bit

    1 Reply Last reply
    0
    • B Offline
      B Offline
      b1gsnak3
      wrote on last edited by
      #2

      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)

      1 Reply Last reply
      0
      • U Offline
        U Offline
        udx6bs
        wrote on last edited by
        #3

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

        Using Qt5.02/32bit on Windows Win7/64bit

        1 Reply Last reply
        0
        • B Offline
          B Offline
          b1gsnak3
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • U Offline
            U Offline
            udx6bs
            wrote on last edited by
            #5

            Thx, will try it.

            Using Qt5.02/32bit on Windows Win7/64bit

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved