Skip to content
  • 0 Votes
    2 Posts
    2k Views
    SGaistS

    Hi,

    Can you show your .pro file ?

  • 0 Votes
    5 Posts
    5k Views
    ?

    Thanks, that was exactly what I was looking for. Works like a charm now!

  • 0 Votes
    3 Posts
    1k Views
    T

    @the_
    no it is Qt::ScrollBarAsNeeded.but scrolbar appears correctly after I resize the main widget even with 1 px.

  • 0 Votes
    5 Posts
    4k Views
    T

    Well seems that it needs to emit model's layoutChanged() to do what I need. I created new class which inherits QListWidget and there I connected signal to layoutChanged signal of model() object and it worked.

  • 1 Votes
    7 Posts
    30k Views
    VRoninV

    @kishore_hemmady said in QListWidget delete selected item:

    how can i achieve this by selecting the check Box rather than selecting the list content?

    for(int i=ui->listWidget->model()->rowCount()-1;i>=0;--i){ if(ui->listWidget->model()->index(i,0).data(Qt::CheckStateRole).toInt()==Qt::Checked) ui->listWidgetMy->model()->removeRow(i); }
  • 0 Votes
    2 Posts
    2k Views
    Chris KawaC

    Put the list widget in a layout. Here's more on layouts in Qt.

  • 0 Votes
    5 Posts
    4k Views
    alextekeufA

    @SGaist

    Thank you for your answer, I'm gonna try in this way.

    If it works, i'll post it here because I'm sure it could be helpfull for someones... I'm actually surprise to see that it's not implemented within the QListWidget class!

  • 0 Votes
    3 Posts
    3k Views
    A

    Thanks for your suggestion. I will try this one.

  • 0 Votes
    4 Posts
    3k Views
    Gianluca86G

    I get it. Thanks so much

  • 0 Votes
    12 Posts
    8k Views
    M

    Finally... After few docs and experiences, I don't know how but I missed the fact that QWidgets are not reentrant (thanks to @kshegunov), and I also missed the fact that signals and slots are made for that.

    @SGaist So, thanks for your advices but doing real MVC made my app too complicated for what it does. In a more constructed project, I would do what you suggested. I've simplified mine:

    Choose your "root" directory The Crawler crawls (recursively in Qt::Concurrent) and send a signal when the QFileInfo::fileName().length() is more than x characters A slot in the MainWidget adds the item in the QListWIdget

    That's all for now (auto-rename for later), so few lines of code. Thank you for your advices.

  • 0 Votes
    12 Posts
    5k Views
    SGaistS

    It's good when it's more friendly :)

  • 0 Votes
    6 Posts
    6k Views
    R

    I have added these few lines to resemble GIF image as background for QListWidget

    QPixmap pix = QPixmap::grabWidget(ui->label,20,30,741,481); pix.fill(Qt::transparent); QPalette p; p.setBrush(QPalette::Base,pix); p.base();
  • 0 Votes
    7 Posts
    6k Views
    F

    @raven-worx Thanks. I ended up using this solution, which seems a bit more direct and focused than overriding "select".

  • 0 Votes
    4 Posts
    3k Views
    kshegunovK

    @Franz-Amador
    No problem. If you've edited the Qt sources fixing the bug, and have the time, you could also submit that patch through the gerrit code review, although it requires some work to clone/setup the repository.

    Kind regards.

  • 0 Votes
    2 Posts
    2k Views
    M

    I fixed this issue depending on the mentioned snippet here:
    http://www.qtcentre.org/threads/53580-TapAndHoldGesture-sender-object-name

  • 0 Votes
    10 Posts
    7k Views
    S

    Hi
    Thank you. you helped so much. And if I can't fix the scrollbar problem I will ask it in forum

  • 0 Votes
    5 Posts
    3k Views
    Chris KawaC

    So do you want all paths or only the selected in input ones?
    For selected you would do:

    auto items = ui->listWidgetinput->selectedItems(); for(auto item : items) { auto path = item->data(Qt::UserRole).toString(); ui->listWidgetOutput->addItem(path); }

    For all you would do:

    auto numItems = ui->listWidgetinput->count(); for(int i = 0; i < numItems; ++i) { auto path = ui->listWidgetinput->item(i)->data(Qt::UserRole).toString(); ui->listWidgetOutput->addItem(path); }
  • 0 Votes
    6 Posts
    5k Views
    L

    @Lorence now its working, i dont know what happens yesterday

  • 0 Votes
    6 Posts
    2k Views
    R

    It is not the iterator that is the problem. From your example:

    for ( QList<QListWidgetItem*>::iterator iter = selectedItems().begin(); iter != selectedItems().end(); iter++ ) { qDebug() << (*iter)->text(); }

    The functions 'selectedItems().begin()' and 'selectedItems().end()' are the problem. Each time you call 'selectedItems()' a copy of QList<QListWidgetItem*> array is returned. Since you call it twice you have two different copies. The contents of the list may be the same but they are two different lists.

    Consider this:

    QString input_text(" some text for input "); QString text = input_text.simplified().trimmed().mid(1);

    In order to have the second line work a QString is constructed (and destroyed) for each step as a copy constructor. The QString member 'simplfied()' returns an unnamed instance of a new copy of QString after performing whatever 'simplfied()' does. The member 'trimmed()' is then called from this new QString creating another unnamed instance which finally calls member 'mid(1)'. The final variable 'text' is assigned from the last member function of the unnamed instance of QString. If the last member was '.toInt()' it would return an integer instead (which won't compile unless the assigned variable is changed to an integer (or acceptes an integer as a constructor)).

    The output from the above example is "ome text for input" if you are curious.

    The member function QListWidget::selectedItems(void) might looks something like this:

    QList<QListWidgetItem*> QListWidget::selectedItems(void) const { QList<QListWidgetItem*> list; list.push_back(<figure out what is selected>); return list; }

    You end up calling this function twice and therefore you have two different lists as you would expect (returned values from the same function will each have a unique instance). Your loop starts on the beginning of the first list and ends on the last item of the second list. It is very likely they are not sitting next to each other in memory so after the first list is traversed you are running over unknown memory (which is where your segfault comes from).

    You need to be careful about copy constructors (when they are created). For example, your 'for' loop uses the postfix operator 'iter++'. For simple variables (integers) this is not a problem but if you have a complex iterator calling the postfix version will be expensive at it creates a copy. A better form is to use the prefix operator '++iter' as no copy is created.

  • 0 Votes
    2 Posts
    1k Views
    mrjjM

    @Lorence said:

    Hi when you add "xxxx" to a qlistwidget
    you are adding a QListWidgetItem.

    While you can subclass QListWidgetItem and make your own
    that has signals, it would not do you so much good as

    it would never never emit such signal unless you also made it do
    so when something happen to it. (overriding some of its functions)

    So It all depends what you are trying to do.
    If you just want to know its no 1,2,3 etc, even if moved
    then
    you can insert that info into the QListWidgetItem using the
    void QListWidgetItem::setData(int role, const QVariant & value)

    something like
    QListWidgetItem * item=new QListWidgetItem("item1") ;
    item->setData(Qt::UserRole, 1); // or 2 for item 2 etc
    list->addItem(item)

    then you can always know which is which even if rearranged.
    see here for how to take index out also
    http://stackoverflow.com/questions/7136818/can-i-store-some-user-data-in-every-item-of-a-qlistwidget