qlineedit

How to accomplish drop down word suggestions in Qt?

懵懂的女人 提交于 2019-12-18 13:25:35
问题 Say I have 10 names in a QListWidget (which is hidden) and an a QLineEdit . Now if I type the letter "a" in the line Edit it should display a drop down of all those name in the list widget that begin with the letter "A". the user could select using a mouse or a keyboard (since there will be a vertical scroll-bar). I am not sure if a QLineEdit could do this. But I would like to know what is out there to accomplish this. 回答1: You can use QCompleter which provides a way for autocompletion in

How to insert a button inside a QLineEdit

人盡茶涼 提交于 2019-12-17 18:47:15
问题 I need help inserting a button inside in a QLineEdit that can call a function. For example, like this google image: 回答1: Below is a nearly direct translation of the Qt code from here. Differences: button is always visible clicking on the button emits buttonClicked(bool) signal Code: from PyQt4 import QtGui, QtCore class ButtonLineEdit(QtGui.QLineEdit): buttonClicked = QtCore.pyqtSignal(bool) def __init__(self, icon_file, parent=None): super(ButtonLineEdit, self).__init__(parent) self.button =

Qt: QLineEdit cursor moves to end after textChanged() or commitData()

好久不见. 提交于 2019-12-12 18:50:43
问题 I have a QTableView with one column that uses a QLineEdit as its editor delegate, and other columns that need to update dynamically as the user types into the QLineEdit (e.g. one of the columns contains the length of the text typed in the QLineEdit and it should update as the user types, not waiting for them to hit Enter to commit). I used this code: Qt: Signal while a QTableView item data is being edited instead of after edit is done? which mostly works. It connects the QLineEdit textChanged

Fail to clear QLineEdit after selecting item from QCompleter

允我心安 提交于 2019-12-12 09:13:45
问题 using PopupCompletion mode when you select an item (using arrow keys) and press return - lineEdit should become empty (i clear lineEdit when return is pressed), but lineEdit does not become empty. (If you press 'Enter' again it will empty the lineEdit). So i think pressing return does clear lineEdit, but pressing return also tells QCompleter to insert selected item into lineEdit, so it seems like nothing happens. But, if you click the item insted of selecting it with arrows - everything works

QString to short using toShort

自作多情 提交于 2019-12-12 06:47:38
问题 I want to convert QString to short.when I try this code ui->lineEdit->text().toShort(); It works well for text = 20 but it returns "0" for value = 20.5. but I need value = 20. how can I solve it? 回答1: The reason that 0 is returned is because a decimal point is an invalid character for the short data type. If you want to be able to convert floating-point numbers from QString to integers, you need to convert your text to a float or double first, then use normal rounding/truncation to convert to

Linking Qline edit with combo box in qt c++

浪子不回头ぞ 提交于 2019-12-12 05:27:22
问题 I want to load the value of book name to a text box when I select the book Id from the comboBox . First I wrote the code for loading Book Ids to comboBox from database and it loaded perfectly. This is the method. void FictionSection::loadComboVal() { DatabaseConnection mydb; QSqlQueryModel *modl = new QSqlQueryModel(); dbConOpen(); QSqlQuery *query = new QSqlQuery(mydb.db) ; query->prepare(" select material_id from fiction "); bool flag = query->exec(); //assigning the values to a QTableView

PyQt4: AttributeError: 'QLineEdit' object has no attribute 'setPlaceholderText'

十年热恋 提交于 2019-12-12 02:09:53
问题 I have a QLineEdit, and I want to set a placeholder text. When I call setPlaceholderText(string) I get an AttributeError, but: >>> from PyQt4 import QtCore >>> QtCore.PYQT_VERSION_STR '4.7.4' >>> QtCore.QT_VERSION_STR '4.7.0' and from the QAssistant: This property holds the line edit's placeholder text. ... This property was introduced in Qt 4.7. 回答1: I would guess that although the libraries are very recent, the bindings are simply not that up to date. You might want to check out PySide - a

How to make a QLineEdit follow the cursor to show me its coordinates

风格不统一 提交于 2019-12-11 22:51:38
问题 I want my QWidget to show me the coordinates of my cursor when it's on the Image, I read that the best way is to use QLineEdit , but I didn't find how to use it to do so. How to initiate the QLineEdit and how to show it, in order that it follows the cursor ? PS : I know how to set the points coordinates on it. this is how i'm doing it : void QImageWidget::mouseMoveEvent( QMouseEvent *event ){ int x = event->pos( ).x(); int y = event->pos( ).y(); if( cursorLineEdit != NULL && cursorLineEdit-

Getting a string out of QLineEdit

社会主义新天地 提交于 2019-12-11 16:56:58
问题 I am quite new to the coding and have been just learning Python 3 and PyQt5 for several days. I am now coding a little prog for my friend who has to fill in very long forms for his job. I want the prog to write huge paragraphs of text for him, with him only entering the needed data. Everything has been running perfectly well and I had no problems, but now I am just spending hours not being able to get how to turn a QLineEdit-piece into a string type of data. Here is an extract of my code.

how to notify that the maxlength is overflowing

只谈情不闲聊 提交于 2019-12-11 07:53:26
问题 Is there a way to connect a signal before executing a default handler? I'm looking for a way to execute my function prior to QLineEdit::textChanged signal to execute notification about maximum length limit. GTK+ has connect_before(), connect() and connect_after(). Is there something similar in Qt? 回答1: You can use the keyPressEvent method to issue the custom signal. #include <QtWidgets> class LineEdit: public QLineEdit { Q_OBJECT public: using QLineEdit::QLineEdit; signals: void