Important: Please read the Qt Code of Conduct -

QListWidget VS QTableWidget

  • Hi
    I'm working on a musicplayer and I want to be able to show the albums like Itunes does. So which one should I use? QListWidget or QTablewidget?

    I tried QListWidget but when you resize the window the albums don't fill the empty space

  • Lifetime Qt Champion

    The real difference is model / view thing

    Maybe you need to use some layout for it to resize.
    A picture would be helpfull

  • Hi
    I meant this:

    And while we're at it could you tell me what is causing the scrollbar to look like that?

    And also what should I use for displaying tracks in an album?
    I'd use QListwidget but it can't show tracknumber and rating and ...

  • Lifetime Qt Champion


    If you place the qlistwidget in a layout, it will use all the space
    it can get from mainwindow. and follow when window is resized.

    -causing the scrollbar to look like that?
    Not sure what is wrong with it. ? Scrollbars looks like on the platform
    so what is wrong look-wise with this one?
    Did you use a style sheet on mainwindow?

    --or displaying tracks in an album?
    It is possible to use a Delegate for custom drawing.
    So you could make your own delegate to draw the
    tracks info as you want to.
    Here is example.
    this one is also good for minimal sample

  • I used Qt Designer for the ui and i used it in a horizontal layout.
    I set the gridsize of the QListItemWidget to 150x150 and the icon size to 120x120. could this be the problem?

    and the scrollbar:
    In GTK style the scrollbar does not look like that. I also used fusion style this way(on both ubuntu and fedora):
    at the top of the in the Music class constructor but it didn't change. what should I do?

    and for displaying tracks in an album I meant the master detail example in Qt Examples. but the example is too complicated. is there a simple way to do it?

  • Lifetime Qt Champion

    --used it in a horizontal layout.
    It seems you are right. It only seems to make two "columns"
    even there is space for more. (when using grid size)
    Not sure why. will check.

    have u check what QStyleFactory::create("Fusion") returns ?
    Maybe it fails somehow. Also for test. set it directly on scrollbar?

    -- tracks in an album
    Well if you have your information in DB and in an XML file, it would be
    something like that.
    But how complex it gets depends on how you store the data and it what ways you need to mix it.
    So it depends on how you design your application.

  • Lifetime Qt Champion

    There is resizeMode (property) and if u set to Adjust it will use all space.
    Also maybe set Flow to LeftToRight

  • Hi
    the resizeMode Worked. thank you veeeeery much.
    And the fusion style works because it changes the sliders I used for volume and position slider. I also tried:


    And it did not worked.

    And because I don't know how to work with SQL I'm temporarely using text files right now but I will learn and use SQL in my app. Is there an easier example than QT Sql examples?

  • Lifetime Qt Champion

    Not sure what that scrollbar is acting up.
    should take style from parent.

    Regarding SQL
    Is its the actual SQL then maybe

    For Qt please see this small example (thank you to @DanRubery)

        QString sql;
        QString filename = "c://people.db";
        QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
        if (!
            qDebug() << db.lastError().text();
        QSqlQuery  q0;
    // here we define a table with personID and name
        sql = "CREATE TABLE People ("
              "PersonId INTEGER PRIMARY KEY,"
              "Name VARCHAR(100)"
    // here we make a Query and use it to insert bob
        QSqlQuery q1;
        sql = "INSERT INTO People (Name) VALUES ('Bob')";
        if (!q1.exec(sql)) {
            qDebug() << q1.lastError().text();   
    // this is using a placeholder for inserting "Dan"
        QSqlQuery q2;
        sql = "INSERT INTO People (Name) VALUES (':a')";
        if (!q2.prepare(sql)) {
            qDebug() << "Unable to prepare";
        q2.bindValue(":a", "Dan");
        if (!q2.exec()) {
            QString msg;
            msg = "'" + q2.lastError().text() + "' when executing '"+ q2.executedQuery() + "'";
            qDebug() << msg;

    So storing the record info dont have to be huge project.

    May I suggest to download

    It allows you to open the db and browser it. it can also run SQL statements so it a
    handy tool for development.

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