Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QListWidget VS QTableWidget
QtWS25 Last Chance

QListWidget VS QTableWidget

Scheduled Pinned Locked Moved Solved General and Desktop
qlistwidgetqtablewidgetmusic
10 Posts 2 Posters 7.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    shahriar25
    wrote on 31 Dec 2015, 16:54 last edited by
    #1

    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

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 31 Dec 2015, 17:01 last edited by
      #2

      Hi
      The real difference is model / view thing
      http://doc.qt.io/qt-5.5/model-view-programming.html

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

      1 Reply Last reply
      1
      • S Offline
        S Offline
        shahriar25
        wrote on 1 Jan 2016, 07:56 last edited by
        #3

        Hi
        I meant this:

        http://i65.tinypic.com/2dhfjp3.jpg

        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 ...

        M 1 Reply Last reply 1 Jan 2016, 10:53
        0
        • S shahriar25
          1 Jan 2016, 07:56

          Hi
          I meant this:

          http://i65.tinypic.com/2dhfjp3.jpg

          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 ...

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 1 Jan 2016, 10:53 last edited by
          #4

          @shahriar25

          Hi
          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.
          http://doc.qt.io/qt-5/examples-layouts.html

          -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.
          http://doc.qt.io/qt-5/qtwidgets-itemviews-stardelegate-example.html
          this one is also good for minimal sample
          http://stackoverflow.com/questions/6905147/qt-qlistwidgetitem-multiple-lines

          1 Reply Last reply
          1
          • S Offline
            S Offline
            shahriar25
            wrote on 1 Jan 2016, 14:16 last edited by shahriar25 1 Jan 2016, 14:17
            #5

            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):
            this->setStyle(QStyleFactory::create("Fusion"));
            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?

            M 1 Reply Last reply 1 Jan 2016, 14:33
            0
            • S shahriar25
              1 Jan 2016, 14:16

              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):
              this->setStyle(QStyleFactory::create("Fusion"));
              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?

              M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 1 Jan 2016, 14:33 last edited by
              #6

              @shahriar25
              Hi
              --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.

              --scollbar.
              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.

              1 Reply Last reply
              1
              • M Offline
                M Offline
                mrjj
                Lifetime Qt Champion
                wrote on 1 Jan 2016, 14:36 last edited by mrjj 1 Jan 2016, 14:38
                #7

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

                1 Reply Last reply
                2
                • S Offline
                  S Offline
                  shahriar25
                  wrote on 1 Jan 2016, 16:49 last edited by
                  #8

                  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:

                  ui->albumListWidget->setStyle(QStyleFactory::create("Fusion"));

                  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?

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on 2 Jan 2016, 11:00 last edited by mrjj 1 Mar 2016, 11:28
                    #9

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

                    Regarding SQL
                    Is its the actual SQL then maybe
                    http://beginner-sql-tutorial.com/sql.htm

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

                        QString sql;
                        QString filename = "c://people.db";
                        QFile::remove(filename);
                    
                        QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
                        db.setDatabaseName(filename);
                        if (!db.open())
                        {
                            qDebug() << db.lastError().text();
                            return;
                        }
                    
                        QSqlQuery  q0;
                    // here we define a table with personID and name
                        sql = "CREATE TABLE People ("
                              "PersonId INTEGER PRIMARY KEY,"
                              "Name VARCHAR(100)"
                              ")";
                        q0.exec(sql);
                    // 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
                    http://sourceforge.net/projects/sqlitebrowser/

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

                    1 Reply Last reply
                    1
                    • S Offline
                      S Offline
                      shahriar25
                      wrote on 3 Jan 2016, 08:15 last edited by
                      #10

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

                      1 Reply Last reply
                      1

                      1/10

                      31 Dec 2015, 16:54

                      • Login

                      • Login or register to search.
                      1 out of 10
                      • First post
                        1/10
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved