×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Regular Contributor
    Join Date
    May 2009
    Posts
    146

    Push size of QListWidget

    I have two QListWidgets inside a QScrollArea.

    As you can see when the items in the lists doesn't fit into the list it either shows a scroll bar (like List 1) or the itmes that don't fit will not be shown at all (like List 2). What I want instead is that if the items doesn't fit they should push the QListWidget to be larger vertical and that no scroll should be shown at all at the QListWidgets. Instead (if the lists doesn't fit into the scroll area) a scroll should be shown for the whole QScrollArea instead. Is it possible to push the size of the QListWidgets like this?

    Another question regarding QScrollArea. When I want to scroll the area I need to use the scroll to the right. Is it instead possible to make the QScrollArea to be able to scroll when touching and holding inside the QScrollArea and not use the scroll to the right?

  2. #2
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: Push size of QListWidget

    Your UI design is pretty much user unfriendly. However, this is an interesting theoretical task.
    I failed to solve it for now This is my test example:

    Code:
    #include <QApplication>
    #include <QMainWindow>
    #include <QListWidget>
    #include <QVBoxLayout>
    #include <QScrollArea>
    #include <QDebug>
    
    int
    main (int argc,
          char **argv)
    {
        QApplication app(argc, argv);
    
        QListWidget *list1 = new QListWidget;
        for (int i = 0; i < 10; i++) {
            list1->addItem(QString("Item %1").arg(i));
        }
    
        QListWidget *list2 = new QListWidget;
        for (int i = 0; i < 10; i++) {
            list2->addItem(QString("Item %1").arg(i));
        }
    
        QVBoxLayout *vbox = new QVBoxLayout;
        vbox->addWidget(list1);
        vbox->addWidget(list2);
    
        /* Attemt #1 - doesn't work */
        list1->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
        list2->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
    
        /* Attemt #2 - also doesn't work */
    /*
        int top, bottom;
        list1->getContentsMargins(0, &top, 0, &bottom);
        list1->setMinimumSize(0, list1->sizeHintForRow(0) * list1->count() + top + bottom);
        list1->getContentsMargins(0, &top, 0, &bottom);
        list2->setMinimumSize(0, list2->sizeHintForRow(0) * list2->count() + top + bottom);
    */
    
        QWidget *widget = new QWidget;
        widget->setLayout(vbox);
    
        QScrollArea *scroll = new QScrollArea;
        /* This also doesn't work for some reason */
        scroll->setMaximumSize(200, 200);
        scroll->setWidget(widget);
    
        QMainWindow win;
        win.setCentralWidget(widget);
        win.show();
    
        return app.exec();
    }

  3. #3
    Regular Contributor
    Join Date
    Mar 2009
    Posts
    430

    Re: Push size of QListWidget

    I think this is not possible using "standard" Qt. You might be able to archive this, but with a lot of effort.

    The general idea is to set the minimum size of listview to the size of the scrolling widget.

  4. #4
    Regular Contributor
    Join Date
    Nov 2008
    Posts
    138

    Re: Push size of QListWidget

    Hello,

    I have faced same problem.

    Basically I would like to make a view where you can open and close QListWidget by pressing a QPushButton on the top of QListWidget. See following:

    <QPushButton>
    <QListWidget>
    <QListWidgetItems...>
    <QPushButton>
    <QListWidget>
    <QListWidgetItems...>
    <QPushButton>
    <QListWidget>
    <QListWidgetItems...>

    I have also used QPropertyAnimation for animating QListWidget closing and opening. It looks very nice when you add setEasingCurve(QEasingCurve::OutBounce).

    What could be alternative solution to solve above problem, if QScollArea cannot handle QListWidgets properly?

    Regards,
    FoL

  5. #5
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: Push size of QListWidget

    Quote Originally Posted by forceoflight View Post
    What could be alternative solution to solve above problem, if QScollArea cannot handle QListWidgets properly?
    What do you mean by QScollArea cannot handle QListWidgets properly? You are misusing widgets in your UI design.

  6. #6
    Regular Contributor
    Join Date
    Nov 2008
    Posts
    138

    Re: Push size of QListWidget

    Do we have a UI component that acts like a QListWidget but it doesn't have scrollbar at all? Perhaps we have container widget? Or do I have to implement custom container widget ? Perhaps that is the only way to make view I would like to have.

Similar Threads

  1. [moved] Receiving WAP Push message
    By doctordwarf in forum Symbian Networking & Messaging (Closed)
    Replies: 10
    Last Post: 2008-10-01, 06:20
  2. Size invalid on screen switch
    By Klaim in forum Symbian User Interface
    Replies: 0
    Last Post: 2006-08-22, 11:20
  3. A Different Jar Size Limit Problem
    By cicdem in forum Mobile Java General
    Replies: 0
    Last Post: 2004-06-17, 15:01

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×