PDA

View Full Version : QListWidget size



dubstar_04
6th March 2010, 17:41
I have tried finding the answer to this and as a last resort i am posting here to see if any one can help.

I have a QLlstWidget to which I add 4 QListWidgetItems

I want to set these QListWidgetItems to fill the space available in the list

I am trying to do the following:

QListWidgetItem->setSizeHint(QSize((listWidget->width()),(listWidget->height()/4)));

however, listWidget->height() returns a size much bigger than the QListWidget.

Is this a bug or am i implementing this wrong?

dubstar_04
7th March 2010, 22:23
does anyone have any advice to solve my problem?

aamer4yu
8th March 2010, 06:11
Try to check the area of the viewport QAbstractScrollArea::viewport
It might be that the QListWidget has more area and scrollbars will be used to navigate it. So check what you get with the viewport

dubstar_04
8th March 2010, 18:32
Thanks for the reply, however that still hasnt solved my problem.

it might make it easier for you to advice if you can see some code;

This is the code from the function that sets up the ui and its elements;




// Setup Pages
mainMenuWidget = new QWidget(this);
timelineWidget = new QWidget(this);
directMessagesWidget = new QWidget(this);
searchWidget = new QWidget(this);
settingsWidget = new QWidget(this);

// Setup Layouts
mainLayout = new QVBoxLayout;
mainMenuLayout = new QVBoxLayout(this);
timelineLayout = new QVBoxLayout(this);
directMessagesLayout = new QVBoxLayout(this);
searchLayout = new QVBoxLayout(this);
settingsLayout = new QVBoxLayout(this);

// Setup visual widgets
timelineLabel = new QLabel("Timeline",this);
directMessagesLabel = new QLabel("Direct Messages",this);
searchLabel = new QLabel("Search", this);
settingsLabel = new QLabel("Settings", this);
backButton = new QPushButton("Back");

// Setup the Mainmenu
QListWidget *listWidget = new QListWidget(this);
//listWidget->setMinimumSize(this->width(), this->height());
std::cout << listWidget->width() << " " << listWidget->height() << std::endl;
std::cout << this->width() << " " << this->height() << std::endl;
listWidget->setAlternatingRowColors(true);



I then add the listwidgetitems to the list.

The widget is set to showMaximized(); and i want to make the listwidgetitems fit nicely regardsless of the screensize that the app is running on.




QListWidgetItem *timelineButton = new QListWidgetItem(listWidget, 1000);
timelineButton->setIcon(QIcon(":/images/menu/timeline.png"));
timelineButton->setText("Timeline");
//timelineButton->setFont(QFont("Lucida Grande", (listWidget->height()/10), QFont::Bold));
timelineButton->setTextAlignment(Qt::AlignCenter);
//timelineButton->setSizeHint(QSize(0,((listWidget->height())/4)));
listWidget->addItem(timelineButton);

the calls to listWidget->height(); and listWidget->viewport->height(); always return the same value regards of what size the widget is set to start at.

for example if i w.resize(400,500); before calling w.show() the size return is the same as when the window is started with w.showMaximized();


Does this shed anymore light on the problem?

Thanks,

Dubstar_04

dubstar_04
9th March 2010, 21:44
This is what i am aiming to achive. A filled QListWidget with no scroll bars and the QListWidgetItems filling the QListWidget neatly and properly.

http://lh6.ggpht.com/_yGkw0Cr-R9E/S5aymWlqMLI/AAAAAAAAB8M/nfn2P1V6MLo/app2.png

Is there a better way to get a nice finger friendly menu?

aamer4yu
10th March 2010, 05:46
For listwidget with no scroll bar, check out for flick charm demo in Qt Labs. Or you may be able to find you might find flickable example in Qt demos from 4.6.2.
For finger friendly you need to have bigger height of items. Arent you getting the same with setSizeHint ?

dubstar_04
10th March 2010, 19:01
Thanks for the flick charm example it looks great, however, it still doesnt answer my initial question of how to size a predefined number of QListWidgetItems to fill a static list.

if you could help me solve this i would be very grateful.

Thanks,

Dubstar_04

aamer4yu
11th March 2010, 05:49
I will try an example if I get time.. meanwhile can you tell how would you want to fill listwidget with height say 600 and having 10 items with height say 60. But if listwidget size get reduced to 200, would you want item height to be 20 ?

Meanwhile I had few questions...
why did you have - //timelineButton->setSizeHint(QSize(0,((listWidget->height())/4))); ?
instead of zero, it should have been timelineButton->->sizeHint().width() I guess... try that and see if it works..

dubstar_04
11th March 2010, 13:41
I will try an example if I get time.. meanwhile can you tell how would you want to fill listwidget with height say 600 and having 10 items with height say 60. But if listwidget size get reduced to 200, would you want item height to be 20 ?

Yes that is exactly what i am trying to do. Size the list items according to the listwidget size.

Meanwhile I had few questions...
why did you have - //timelineButton->setSizeHint(QSize(0,((listWidget->height())/4))); ?
instead of zero, it should have been timelineButton->->sizeHint().width() I guess... try that and see if it works..

I actuall had it as:


timelineButton->setSizeHint(QSize((listWidget->width()),((listWidget->height())/4)));

I would really appreciate it if you could asist me in finding a solution as i seem to have hit a wall with this yet i am sure the solution will be simple.

Thanks,

Dubstar_04