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. QComboBox confusion
QtWS25 Last Chance

QComboBox confusion

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 778 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.
  • E Offline
    E Offline
    eddyilg
    wrote on last edited by
    #1

    I am trying to implement a zoom select with QComboBox. Lets assume there are the following items in the combo box:
    25% -> should lead to a signal setZoom(25)
    50% -> should lead to a signal setZoom(50)
    100% -> should lead to a signal setZoom(100)

    So far, so good. Now comes the challenge: The combo should be editable. When the user types 80 <ENTER>, a signal setZoom(80) should be emitted and the text in the combo should be set to "80%", but NO new item should be added to the drop down menu.

    I have fiddled with different events of QComboBox and the QLineEdit inside but I can't see how to do this. Any hints?

    Cheers,

    Eddy

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi,

      Did you try setting "insertPolicy":http://qt-project.org/doc/qt-4.8/qcombobox.html#insertPolicy-prop to QComboBox::NoInsert ?

      157

      1 Reply Last reply
      0
      • Chris KawaC Online
        Chris KawaC Online
        Chris Kawa
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Something like this should work:
        @
        ui->comboBox->setEditable(true);
        ui->comboBox->setInsertPolicy(QComboBox::NoInsert);

        connect(ui->comboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
        [=](int index){
        emit setZoom(getZoomFromText(ui->comboBox->itemText(index)));
        });

        connect(ui->comboBox->lineEdit(), &QLineEdit::returnPressed,
        ={
        emit setZoom(getZoomFromText(ui->comboBox->lineEdit()->text()));
        });
        @

        Edit ups, too slow :)

        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