I wanna use a self-defined list item in QListWidget.
This item is quite simple, inherited from QWidget,has a QPushButton,a label, and a QHBoxLayout to contain them.
The code is shown in pic I uploaded.
Then,I use create a QListWidgetItem , and use ui.listWidget.setItemWidget. The result is odd,there's no label neither button in the list.
Related
I want to create a QDialog with Qt that looks somewhat like this:
The desired properties here are:
I can add a text to the dialog explaining the question behind it
I can add several buttons that are in a vertical layout
I can retrieve the value of the clicked button, i.e. I know if the user cancelled or clicked 1, 2 or 3 - ideally I can emit a signal with the corresponding value as parameter.
The dialog has a certain minimum height and width.
I have used a QMessageBox before for this purpose, but I can't get it to use a vertical layout. I have experimented with a QDialogButtonBox and a QDialog, but I can't really figure out how to get my desired return value easily.
A piece of code creating this dialog with code how to retrieve the clicked value would be great!
Did you try a QDialog widget? you can add QDialog without buttons to your project. In UI designer, add Vertical layout, label, and buttons.
In your class define your signals and emit it when the user clicked on buttons.
I'm having trouble trying to move the QCompleter popup view position.
I tried the QCompeter:complete and it's pops the completer view in the position as I wanted.
But if I start typing it close it, and open the completer in the 'default' position.
I also tried the QCompleter:setPopup() function.
I create a QListView and I tried to moved to different position.
And still the QCompleter popup view remains in the same position.
In my project I'm using a QFrame that wrap QLineEdit.
And I want that the completer view will get the QFrame position.
I succeed to set the completer view width via setFixedWidth() function.
but not to move the position.
Any suggestions ?
Thanks.
I suggest setting the CompletionMode to InlineCompletion, so there will be no popup. Then make your QListView indepedant of the QLineEdit; just react to signals that indicate when a view types some text, leaves the QLineEdit, etc (hint: subclass QListView) and sets the text in QLineEdit when a user selects a value from the list.
I think it will be difficult to override the placement since QCompleter takes ownership of your QListView. (Personally I think it does not make much sense to place the completion list somewhere else than next to the input field, but alas...)
How can I save the QTreeWidget column order ?
I know it can be done via QTreeView from this post
HowTo make restoreState() and saveState() work correctlly to QTableView class?
but I don't see how I can do it with QTreeWidget.
Any suggestions ?
A QTreeWidget is a QTreeView (it inherits it), so any function you can call on a QTreeView, you can also call on a QTreeWidget.
You can get the (only) header from a QTreeView (and therefore also from a QTreeWidget) using its QTreeView::header() member function. For example:
QTreeWidget *treeWidget = new QTreeWidget(this);
QByteArray saved = treeWidget->header()->saveState();
I want to set the icon on the left side of the QCombobox widget. I know I can insert a item first and then set the icon of the inserted item and then select this newly inserted item. However, I would like to do that without inserting a new item into the drop down list for special reasons. Windows ComboBox control allows us to change the icon of the edit box by using an index of -1. I don't know how to achieve that with QCombobox.
Thanks for any comments!
Never tried it myself, but here is an idea.
QComboBox is based on Qt's model/view framework, so the items are contained into a QStandardItemModel which can be accessed with QComboBox::model().
The steps would be:
Instantiate a QStandardItem
Use setIcon() and setText() on the QStandardItem (or use the proper ctor)
When you want to add the item to the Combo list, append it thru the model.
Example:
QStandardItem* item = new QStandardItem(theIcon, theText);
[...]
QStandardItemModel* comboModel = qobject_cast<QStandardItemModel*>(theCombo->model());
comboModel->appendRow(item);
Suppose I fill some cells of a QTableWidget with buttons:
ui->table->setCellWidget (i, 2, new QPushButton ("Details"));
Just a little bit later I scratch them all and do it again:
ui->table->clear();
Will this buttons get deleted automagically? Or do I need to store a list of them and delete manually? Also, Do I need to specify parent for every button like this: QPushButton ("Details", ui->table)?
The table widget takes ownership of the widget. The documentation states this:
Sets the given widget to be displayed in the cell in the given row and column, passing the ownership of the widget to the table.
You also don't need to specify a parent on creation, that will be set by the tablewidget accordingly.