Skip to content
  • Custom ComboBox not scrolling

    Unsolved QML and Qt Quick
    2
    0 Votes
    2 Posts
    120 Views
    S

    It seems the issue you're experiencing with the ComboBox not scrolling when there are many items is due to the absence of proper height configuration for the ListView inside the Popup. The ListView needs an explicit height to trigger scrolling behavior, and without it, the dropdown won't scroll even when there are many items.

    To fix this, you can add a fixed or constrained height to the ListView, and ensure the ScrollIndicator appears when needed. Here's the updated code for the popup section:

    popup: Popup {
    y: control.height - 1

    width: control.width implicitHeight: contentItem.implicitHeight padding: 0 contentItem: ListView { width: parent.width height: Math.min(200, contentHeight) // Constrain the ListView height or set a max height clip: true model: control.popup.visible ? control.delegateModel : null currentIndex: control.highlightedIndex ScrollIndicator.vertical: ScrollIndicator { visible: contentHeight > height // Only show the scroll indicator if the content exceeds the viewable area } } background: Rectangle { radius: 0 color: Qt.color(AppTheme.colors["UFO_ComboBox_Popup_Background"]) border.color: Qt.color(AppTheme.colors["UFO_ComboBox_DropBox_Border"]) }

    }

  • 0 Votes
    3 Posts
    294 Views
    D

    @Christian-Ehrlicher Hi, I have not manually set any css styling the colours I belive just come from fact I am using ubuntu so I think its just using system colours by default

  • 0 Votes
    6 Posts
    926 Views
    CJhaC

    @raven-worx For me, it seems as it is working. The above code is actually taken from ProxyStyle web page from Qt's website, I just replaced QStyle::SH_UnderlineShortcut with QStyle::SH_ComboBox_Popup. So, I think it is a good approach.

    Subclassing QComboBox would become quite cumbersome as I will have to promote all the combo boxes in my UI to the subclass.

  • 0 Votes
    9 Posts
    760 Views
    S

    @CJha said in QComboBox and smart pointer conflict?:

    But in any case I would like to make sure that it is destroyed before the application exits.

    In general this is a good approach. When you write clean code all resources should be freed by your own application (typically RAII in C++). However, when your application closes the OS will free all memory belonging to the application and removes all file handles of the application. Especially in complex applications it can take quite a while to clean up everything in order. In those cases it is a lot more userfriendly to just exit without the clean up. So, don't worry too much about clean up. Still, you should understand why this happens and how it can be avoided.

  • 0 Votes
    2 Posts
    415 Views
    SGaistS

    Hi and welcome to devnet,

    Without a minimal code example showing what you do it's not possible to see what might be wrong.

  • 0 Votes
    5 Posts
    1k Views
    GrecKoG

    @texasRanger said in read value from combo box to c++ function:

    I have been trying to connect the qml signal of the combo box being changed to the itemChanged slot in c++. but I have had no luck.

    Don't do that.
    Do like in the link posted by SGaist.

    Some links about the reason why you shouldn't reach into QML from C++:

    https://doc.qt.io/qt-5/qtquick-bestpractices.html#interacting-with-qml-from-c
    http://doc.qt.io/qt-5/qtqml-cppintegration-overview.html#interacting-with-qml-objects-from-c
    https://youtu.be/vzs5VPTf4QQ?t=23m20s

  • 0 Votes
    5 Posts
    1k Views
    fcarneyF

    If you use the the same model instance in more than one place they will always have the same index. This may, or may not be what you want. FYI

  • 0 Votes
    3 Posts
    4k Views
    A

    @nagesh No style sheet, however, I had experiemented with the stylesheet in the link that you sent, and I couldn't figure it out. Which fields pertain to the width of the drop-down?

    There is a horizontal layout, however, I have also tried without layout and I get the same issue.
    I can control the width of the Combobox when it is closed, but once open there is an offset, that is what I would like to remove.

    Thank you,
    Arjun

  • 0 Votes
    5 Posts
    691 Views
    Pablo J. RoginaP

    @suslucoder said in Open the selected port:

    I solved it, you can delete my post.

    No, the solved posts don't get deleted. They remain for the benefit of other forum users having same/similar issues.
    It's a community driven approach, opposite to a "my problem only" driven approach

  • 0 Votes
    10 Posts
    2k Views
    jsulmJ

    @suslucoder I don't see why it would not be possible to select other entries in a combo box. Do you do anything else with ui->ports?

  • 0 Votes
    4 Posts
    870 Views
    K

    Thought initially that the issue could be completely solved in qml, but Settings seem to miss some features as present in QSettings. Therefore decided to move forward with solution based on C++ with QML.

    https://forum.qt.io/topic/120954/combobox-together-with-qstringlistmodel

  • 0 Votes
    5 Posts
    2k Views
    C

    @JonB alright.I will remember that

  • 0 Votes
    2 Posts
    383 Views
    B

    count() just return the number of items as the result, what do you expect it to work?
    showPopup() should be called on the combo box, so ui->comboBox->showPopup().
    Are you also new to C++? Feels like you need learn some basics first.

  • 0 Votes
    4 Posts
    576 Views
    SGaistS

    Your BluetoothController should have a member variable of the BluetoothModel class.
    Your BluetoothModel class should provide an API that your BluetoothController can connect to and also that provides whatever data is needed.

  • 0 Votes
    2 Posts
    642 Views
    B

    Update: I downloaded the most recent version of Qt, 5.13.0, and I could not get the issue to repeat. So I think the problem is related to specific versions of Qt.

  • 0 Votes
    2 Posts
    1k Views
    G

    I figured it out:

    displayText: currentIndex === -1 ? "Choose ..." : currentIndex
  • 0 Votes
    2 Posts
    1k Views
    S

    Ok, I have figured it out by myself. The key was looking at the comboBoxModel->data and getting the index from rows and coloumns. That's my solution:

    void comboBoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const { if(QComboBox *cb = qobject_cast<QComboBox*>(editor)) { QString cbText = cb->currentText(); int vpe_index = -1; for (int row = 0; row < comboBoxModel->rowCount() ; row++) { if (comboBoxModel->data(comboBoxModel->index(row, 0)) == cbText){ vpe_index = comboBoxModel->data(comboBoxModel->index(row, 1)).toInt(); } } if (vpe_index == -1) { qDebug() << "Index not found"; } else { qDebug() << "Index set: " << model->setData(index, vpe_index, Qt::EditRole); } } else { QStyledItemDelegate::setModelData(editor, model, index); } }
  • 0 Votes
    9 Posts
    9k Views
    J.HilkJ

    @koahnig said in changing combobox index when selection of another combobox is changed:

    Probably a really stupid question: Why do I need "===" and not "==" ?

    Because you want to be really really sure that they are equal x)

    No, JavaScript does conversion checks as well

    "1" == 1 -> true
    "1" === 1 -> false

    And I love C++!!!

    hear,hear!

  • 0 Votes
    4 Posts
    721 Views
    Christian EhrlicherC

    I said 'Maybe you've a typo...'
    The problem with auto-connect is that you can not be sure if it is really connected (e.g. when there is a typo somewhere in the functions signature or the ui element name) and it easily breaks (e.g. when renaming an ui element).