Skip to content
QtWS25 Last Chance
  • 0 Votes
    5 Posts
    495 Views
    EmrecpE
    Can anyone share sample code for qlistwidget or qlistview?
  • 0 Votes
    6 Posts
    1k Views
    V
    Kind of solved. If I set sizeAdjustPolicy to AdjustToContents and sizePolicy to Maximum, the list widget size will adjust to accomodate items plus small margins around them. I'm quite happy with the result, it would be even better if I could make items equally distribute across available space, but even now it looks good enough.
  • 0 Votes
    4 Posts
    1k Views
    EmrecpE
    @VRonin Yeah you are right. Usually my custom widget has another widgets (like another label for text, button for submit etc.) so I used setItemWidget. But your way better for only images.
  • 0 Votes
    4 Posts
    3k Views
    B
    @learnist said in How to edit a QListwidgetItem by using custom context menu ? need some corrections: but for point 3 ,which edit trigger should i use ?? can you please elaborate If you don't want double clicking or any key pressing to trigger the editing, just set it to QAbstractItemView::NoEditTriggers.
  • 0 Votes
    3 Posts
    2k Views
    SGaistS
    By the way, how are your buttons connected ? You might want to rather call the dialog's accept slot from on_buttonBox_accepted rather than connecting it directly to your button.
  • 0 Votes
    2 Posts
    500 Views
    mrjjM
    Hi 10.000 items take some time to create and add. Print_Descendants_key must not touch/access the ListWidget from the other thread. that will not be good. To make the UI less hanged while adding such a number of items, you can do 3 things. 1: use a View + custom model instead. If you already have all the data in a list/vector, a custom model on top of that would be super fast. 2: Use a thread to send data to main. Make sure the thread is not hammering the main gui as that would lag too. You can also use a QTimer and simply slow down the adding. 3: Do the ugly trick of calling QApplication::processEvents() (in the loop that adds the items) to allow the main GUI to be more responsive.
  • 0 Votes
    4 Posts
    907 Views
    jsulmJ
    @Mr-Workalot said in is there a way to minimize/hide and show the QListWidget in my UI: i guess this can be done when i select 2 widgets atleas Yes. Select the your list widget and the left layout, then you can layout them using splitter...
  • 0 Votes
    3 Posts
    893 Views
    mrjjM
    Hi The downside of having 22 dialogs is all the .cpp and .h you get and also adding new features, say you want to have an image of the dish at some later point you would have to add this 22 places. For your use case, it sounds like data driver would be much better. Meaning you have just one dialog and then based on the data structure where you keep the information about the recipes, you add the needed EditLines at runtime. SO as @JonB asks, are they that special each of the dishes that you cant handle them very much the same?
  • 0 Votes
    5 Posts
    628 Views
    SGaistS
    Good then please mark the thread as solved using the "Topic Tools" button so that other forum users may know a solution has been found.
  • 0 Votes
    5 Posts
    2k Views
    L
    @mrjj Thanks so much , really helped me understand.
  • 0 Votes
    3 Posts
    820 Views
    CybeXC
    @VRonin Doing a few (rather simple) tests, I found the following (which confirms your suspicion) Works: (but no check box) - this is expected to work // create item QListWidgetItem* item = new QListWidgetItem(name, ui->listDriveInfo); // item->setText(name); // item->setFlags(item->flags() | Qt::ItemIsUserCheckable); // item->setCheckState(enabled ? Qt::Checked : Qt::Unchecked); // add item to list ui->listDriveInfo->addItem(item); this crashes on setFlags() call // create item QListWidgetItem* item = new QListWidgetItem(name, ui->listDriveInfo); // item->setText(name); //set checkable and state Qt::ItemFlags localFlags = item->flags(); item->setFlags(localFlags | Qt::ItemIsUserCheckable); item->setCheckState(enabled ? Qt::Checked : Qt::Unchecked); // add item to list ui->listDriveInfo->addItem(item); but these 2 both work (without setting owning QListWidget) // create item QListWidgetItem* item = new QListWidgetItem(name); // item->setText(name); //set checkable and state Qt::ItemFlags localFlags = item->flags(); item->setFlags(localFlags | Qt::ItemIsUserCheckable); item->setCheckState(enabled ? Qt::Checked : Qt::Unchecked); // add item to list ui->listDriveInfo->addItem(item); and // create item QListWidgetItem* item = new QListWidgetItem(); // item->setText(name); //set checkable and state Qt::ItemFlags localFlags = item->flags(); item->setFlags(localFlags | Qt::ItemIsUserCheckable); item->setCheckState(enabled ? Qt::Checked : Qt::Unchecked); // add item to list ui->listDriveInfo->addItem(item); Testing: I create a new application, did exactly the same (add a string and a checkbox) and that work 100%. Create a form, throw on a QListWidget and run it with this code. QListWidgetItem* item = new QListWidgetItem("New", ui->listWidget); item->setFlags(item->flags() | Qt::ItemIsUserCheckable); item->setCheckState(Qt::Unchecked); QListWidgetItem* item1 = new QListWidgetItem("New 1", ui->listWidget); item1->setFlags(item->flags() | Qt::ItemIsUserCheckable); item1->setCheckState(Qt::Unchecked); QListWidgetItem* item2 = new QListWidgetItem("New 2", ui->listWidget); item2->setFlags(item->flags() | Qt::ItemIsUserCheckable); item2->setCheckState(Qt::Unchecked); ui->listWidget->addItem(item); ui->listWidget->addItem(item1); ui->listWidget->addItem(item2); connect(ui->listWidget, &QListWidget::itemClicked, this, [this](QListWidgetItem * i) { // Get drive info from driveList int pos = ui->listWidget->row(i); // check state & set state bool active = i->checkState() == Qt::Checked; qDebug() << (active ? "enabled" : "disabled"); }); So my question is, bug (on whose side) or some setting on my side? Thoughts on what to look for?
  • 0 Votes
    4 Posts
    2k Views
    E
    @mrjj I see, thank you. I'm going for that route then
  • 0 Votes
    6 Posts
    929 Views
    Christian EhrlicherC
    Drag'n'Drop from a QListWidget to another QListWidget should work out-of-the-box if dragEnabled/acceptDrops is active - see documentation
  • 0 Votes
    6 Posts
    2k Views
    R_IrudezuR
    @Ratzz Sorry i can not check your answer as solved answer, Qt forum has a bug about that. I solved my problem, i've already read the topic that you linked here but after you posted it then a read again and i solved my problem thank you, but even so trying to give more explanatory answers is a good way because i like this forum and i want to see answers from another angles, another perspectives. When i get experienced at Qt i want to give good answers too. :) And thank you so much Mr. @dheerendra . I think approach with row is a better way but i was need to a quick way so that stackoverflow link helped me about that.
  • 0 Votes
    6 Posts
    4k Views
    A
    @nebulaekg It wasn't wrong, it was just the easy method. With easy comes very little customization. Now that you want to change it's behavior it becomes much harder. For simple lists you can definitely use the widget but for anything more you want a view/model and then delegates to control display. Check into it I'm sure you'll find it's not that much harder than the widget and will give you the control you want. :)
  • How to disable widget for 1second

    Solved General and Desktop qtcreator qlistwidget
    7
    0 Votes
    7 Posts
    1k Views
    K
    @J.Hilk It works ! THANKS :-)
  • 0 Votes
    8 Posts
    3k Views
    raven-worxR
    @philm001 the stylesheet declaration should rather look like this i guess: w->setStyleSheet(QString("QListView::item { background: rgba(255, 0, 0, %1)}").arg(value.toInt())
  • Optimizations / Substituions for QListWidget?

    Unsolved General and Desktop qlistwidget
    7
    0 Votes
    7 Posts
    2k Views
    VRoninV
    setItemWidget should come with a huge warning about it being the wrong solution in 90% of the cases. What you need is a QStyledItemDelegate. use QListWidgetItem::setData to store your text, image and color in 3 different roles (Qt::EditRole, Qt::DecorationRole and Qt::UserRole appear to be the most natural choices) then subclass QStyledItemDelegate and reimplement paint (you can find Qt's implementation here to use as a starting point) finally just call QListWidget::setItemDelegate to assign the delegate to the view
  • 0 Votes
    5 Posts
    5k Views
    M
    @raven-worx my bad, Thanks for the link it helped a lot.
  • 0 Votes
    8 Posts
    11k Views
    A
    @brucezcg said in QListWidget: How to disable when mouse hover ,the items change background color?: I don't want to change background color when hover, I just want to disable hover, when hover, the items stay the background color, may be different colors, so I couldn't set hover to certain color. Well in that post I linked you on stackoverflow, it shows: QListWidget::item:hover, QListWidget::item:disabled:hover, QListWidget::item:hover:!active, {background: transparent;} That means it just hides the hover, doesn't set it to a certain color. It should do exactly what you need. You can of course make a custom delegate too. That's more work that setting a quick css though.