Skip to content
  • 0 Votes
    3 Posts
    136 Views
    C

    @sayan275 said in QLineedit adding extra \ from text():

    qInfo()<<__FUNCTION__<<textentered;

    When you use the QDebug functions the output is in the form of a C++ literal with anything that would need to be escaped inside the double-quotes, escaped. In this case the backslashes, but also any embedded double quote etc.

  • 0 Votes
    3 Posts
    386 Views
    B

    @SGaist This is the solution! Thank you very much. Below is my new setData() and TextEdited()

    setData()

    bool SummaryModel::setData(const QModelIndex &index, const QVariant &value, int role) { if (index.isValid() && role == Qt::EditRole) { SetSummaryQuantity(value.toInt()); emit dataChanged(index,index); return true; } else { return false; } return false; }

    TextEdited()

    void QueriesCreator::on_quantityGeneralInformationLineEdit_textEdited(const QString &arg1) { calculations.SetMaterialQuantity(ui->quantityGeneralInformationLineEdit->text().toInt()); CalculateMaterialCostInZloty(); summaryModel->setData(ui->summaryDefaultTableView->model()->index(6,0),ui->quantityGeneralInformationLineEdit->text().toInt(),Qt::EditRole); }

    and of course the data()

    QVariant SummaryModel::data(const QModelIndex &index, int role) const { if (role == Qt::DisplayRole) { //Quantity if (index.row() == 0 && index.column() == 0) return QString("50"); if (index.row() == 2 && index.column() == 0) return QString("100"); if (index.row() == 4 && index.column() == 0) return QString("1000"); if (index.row() == 6 && index.column() == 0) return GetSummaryQuantity(); //Currency- byc w moze w przyszlosci zmienic na inne if (index.row() == 0 && index.column() == 1) return QString("PLN"); if (index.row() == 1 && index.column() == 1) return QString("EUR"); if (index.row() == 2 && index.column() == 1) return QString("PLN"); if (index.row() == 3 && index.column() == 1) return QString("EUR"); if (index.row() == 4 && index.column() == 1) return QString("PLN"); if (index.row() == 5 && index.column() == 1) return QString("EUR"); if (index.row() == 6 && index.column() == 1) return QString("PLN"); if (index.row() == 7 && index.column() == 1) return QString("EUR"); //Price Placeholders //Material if (index.row() == 0 && index.column() == 2) return QString("0,00"); if (index.row() == 1 && index.column() == 2) return QString("0,00"); if (index.row() == 2 && index.column() == 2) return QString("0,00"); if (index.row() == 3 && index.column() == 2) return QString("0,00"); if (index.row() == 4 && index.column() == 2) return QString("0,00"); if (index.row() == 5 && index.column() == 2) return QString("0,00"); if (index.row() == 6 && index.column() == 2) return QString("0,00"); if (index.row() == 7 && index.column() == 2) return QString("0,00"); //Machining if (index.row() == 0 && index.column() == 3) return QString("0,00"); if (index.row() == 1 && index.column() == 3) return QString("0,00"); if (index.row() == 2 && index.column() == 3) return QString("0,00"); if (index.row() == 3 && index.column() == 3) return QString("0,00"); if (index.row() == 4 && index.column() == 3) return QString("0,00"); if (index.row() == 5 && index.column() == 3) return QString("0,00"); if (index.row() == 6 && index.column() == 3) return QString("0,00"); if (index.row() == 7 && index.column() == 3) return QString("0,00"); //Diference if (index.row() == 0 && index.column() == 4) return QString("0,00"); if (index.row() == 1 && index.column() == 4) return QString("0,00"); if (index.row() == 2 && index.column() == 4) return QString("0,00"); if (index.row() == 3 && index.column() == 4) return QString("0,00"); if (index.row() == 4 && index.column() == 4) return QString("0,00"); if (index.row() == 5 && index.column() == 4) return QString("0,00"); if (index.row() == 6 && index.column() == 4) return QString("0,00"); if (index.row() == 7 && index.column() == 4) return QString("0,00"); } if(role==Qt::TextAlignmentRole) { return Qt::AlignCenter; } return QVariant(); }

    Now It works as I expect. Thanks and Have a good day!

  • 0 Votes
    6 Posts
    899 Views
    Pl45m4P

    @CJha

    https://stackoverflow.com/questions/26614678/validating-user-input-in-a-qtableview
    (will work for every model/view, I think)

    Here you go :)

  • 0 Votes
    2 Posts
    529 Views
    Pl45m4P

    @HowardHarkness

    Hi there was a similar topic / question few years ago.
    @SGaist explained why there is one additional space after every mask -> to allow text selection by keyboard.
    Of course Ctrl + A kinda "hacks" it (to select all, at least) and if you dont need it, you could implement a workaround, but unfortunately there is no "Qt-way" to switch it off.

    https://forum.qt.io/topic/60633/qlineedit-using-input-mask-with-blank-space-replacement-cursor-select-replacement-char
  • 0 Votes
    6 Posts
    431 Views
    JonBJ

    @BartM
    I am glad you changed approach.

    This new list of pointers was then forwarded to another thread running in the background that iterates through the list, and emits a signal to setStyleSheet that is then received in the main thread.

    I still don't know why you need any thread at all, seems more complicated than it needs to be. But if you're happy that's fine :)

  • 0 Votes
    4 Posts
    2k Views
    nageshN

    @arjun98 said in How do you properly increase QLineEdit increase icon size/:

    ui->searchbar->setClearButtonEnabled(true);
    ui->searchbar->QLineEdit::addAction(QIcon(":/img/icons/icon_search.png"), QLineEdit::LeadingPosition);

    I have tried loading icon to line edit using above code, it's clearly visibile. and image is not blurred.
    try to experiment loading the icon to QLineEdit without any stylesheet being set to it.

  • 0 Votes
    3 Posts
    521 Views
    aha_1980A

    @jsulm That is correct, but I'd first try with the latest Qt 5 version 5.15.2

    Regards

  • 0 Votes
    1 Posts
    270 Views
    No one has replied
  • 0 Votes
    6 Posts
    684 Views
    SGaistS

    Hi,

    exec is a blocking call so basically you modify your dialog content after you dismiss it.

  • 0 Votes
    3 Posts
    892 Views
    A

    Thanks for the insight, still my issue was that you have to double click (mouse or touch) the LineEdit to get its selection. Now in place of LineEdit i have used TextEdit, it works on single click. Thanks again for the reply.

  • 0 Votes
    7 Posts
    2k Views
    nicmoraisN

    Wow! Thank you @JonB, this solved my issue. One more solved topic to the forum.
    Have a nice a nice day!

  • 1 Votes
    6 Posts
    2k Views
    mrjjM

    @Daniel_Contro
    hi
    Good to hear.
    best to set this as solved and make a new one as then its easier for others to search :)

  • 0 Votes
    13 Posts
    4k Views
    oblivioncthO

    My behavior correction patch for this one has also gone through to be available in 6.0/the current dev build

    https://codereview.qt-project.org/c/qt/qtbase/+/312083

    Cheers.

  • 0 Votes
    3 Posts
    872 Views
    mrjjM

    @mikael-larsson
    Hi
    You could try an event filter on the Combobox and call the code for hover effect but
    if your effect is purely stylesheet based then i think you then must send it fake hover event to trigger it or something like that.

    You might also be able to subclass the combo and rig the paintEvent with
    if (someflag)
    option.state |= QStyle::State_MouseOver;

    to trigger hover on command from the event filter/ or combo hover or how you plan to trigger it.

  • 0 Votes
    6 Posts
    1k Views
    LematL

    @Alain38-0 okay, i will use it for another project. thanks.

  • 0 Votes
    3 Posts
    740 Views
    ?

    Thanks, mrjj!
    That's it!

    Merry christmas

  • 0 Votes
    5 Posts
    1k Views
    J

    @mrjj
    Thanks for the welcoming :-)

    Indeed, the QStyledItemDelegate works fine, but only when I use a QTableWidget. So a first solution was to create a QTableWidget with 1 row and 1 column, and insert my delegate inside. The problem with this technique is that it's hard to perfectly mimic a QLineEdit (behavior, style, etc). For instance, with a QTableWidget, there is no simple click on items to enter in edit mode (this is a double click, at least), as far as I know. It's still possible to redefine the behavior, I guess, but it's not worth it. I don't like the whole thing.

    That's why I came up with another idea. This time, I keep my QLineEdit as is, and I add/remove the input mask when having/losing focus. Thanks to that, I'm now able to see the "true" text (without mask format) when I'm not editing it (QLineEdit does not have the focus), while I can see the text (with mask format) when I'm editing it (has focus). I know it's not totally elegant, but I don't think there is an elegant solution at all for this "problem".

    For those interested, a quick example on how to achieve this:
    (1) install an event filter (installEventFilter()) on the QLineEdit
    (2) filter on focus in/out
    (2.1) focus in: add the mask (setInputMask())
    (2.1) focus out: remove the mask and set the text to the value before the mask was removed (because removing the mask erases the text inside the QLineEdit)

  • 0 Votes
    5 Posts
    2k Views
    mrjjM

    Hi
    Yes calling the function directly is actually a better solution in this case.
    Its worth mentioning that the so called slots are 100% normal c++ member functions
    and can be called without any Qt involvement/use of.

    void MainWindow::on_pushButton_clicked() { int value=ui->lineEdit->text().toInt(); // get value Dialog dialog1; dialog1.sendIntData(value); dialog1.exec(); }