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. How can I set round corners to QListVIew items?
Forum Updated to NodeBB v4.3 + New Features

How can I set round corners to QListVIew items?

Scheduled Pinned Locked Moved General and Desktop
12 Posts 3 Posters 7.7k Views 1 Watching
  • 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.
  • T Offline
    T Offline
    tokafr
    wrote on last edited by
    #1

    Hello all!

    I have the QListView with items. when I select the item the item gets highlighted but it has ordinary corners, I want to round the corners how can I so it?

    thank you again!

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      use stylesheets or a custom item delegate and override it's paint method.

      Example stylesheet (untested):
      @
      listView->setStyleSheet(
      "QListView::item:selected {"
      "border: 1px solid #6a6ea9;"
      "border-radius: 3px;"
      "}"
      );
      @

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • T Offline
        T Offline
        tokafr
        wrote on last edited by
        #3

        doesn't do anything :(

        1 Reply Last reply
        0
        • raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          just tested...works for me.

          !http://oi62.tinypic.com/2gtp1yu.jpg(screenshot)!

          @
          QListWidget l;
          l.addItems( QStringList() << "111" << "222" << "333" );
          l.setStyleSheet(
          "QListView::item:selected {"
          "border: 1px solid #6a6ea9;"
          "border-radius: 5px;"
          "color: black;"
          "}"
          );
          l.show();
          @

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          1
          • D Offline
            D Offline
            DBoosalis
            wrote on last edited by
            #5

            Check your syntax again. It works for me
            @MainWindow::MainWindow(QWidget *parent)
            : QMainWindow(parent)
            {
            lv = new QListView(this);
            QStandardItemModel *model = new QStandardItemModel(this);
            QStringList headers;
            model->setHorizontalHeaderLabels(headers);
            model->setRowCount(3);
            QStandardItem *one = new QStandardItem("ONE");
            QStandardItem *two = new QStandardItem("TWO");
            QStandardItem *three = new QStandardItem("THREE");

            model->setItem(0,one);
            model->setItem(1,two);
            model->setItem(2,three);
            
            
            lv->setStyleSheet("QListView::item:selected {background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 #004400, stop: 1 #00ff00); border: 1px solid #990033; border-radius: 6px;}");
            
            lv->setModel(model);
            setCentralWidget(lv);
            

            }@

            1 Reply Last reply
            0
            • T Offline
              T Offline
              tokafr
              wrote on last edited by
              #6
              • raven-worx*
                there you have QListWidget, Does it work for QListView also because here with me it doesn't do that
              1 Reply Last reply
              0
              • raven-worxR Offline
                raven-worxR Offline
                raven-worx
                Moderators
                wrote on last edited by
                #7

                [quote author="tokafr" date="1422478813"]* raven-worx*
                there you have QListWidget, Does it work for QListView also because here with me it doesn't do that [/quote]

                QListWidget derives from QListView, so yes it does work also with it.
                To be more specific the item selector works for almost all QAbstractItemView widgets.

                Then post some code, maybe we can spot something.

                --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                If you have a question please use the forum so others can benefit from the solution in the future

                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  tokafr
                  wrote on last edited by
                  #8

                  @
                  listWidget = new QListView(this);

                  listWidget->setSelectionBehavior(QListView::SelectRows);
                  listWidget->setEditTriggers(QListView::AllEditTriggers);
                  
                  
                  /* here we set the initial data by hand. */
                  
                  Connection conn1("toka","cloud","http","linux","192.168.1.108");
                  Connection conn2(QObject::tr("localhost"),QObject::tr("Server"),QObject::tr("ssh"),
                                       QObject::tr("windows"),QObject::tr("192.168.1.254"),QPixmap(":/icons/images.png"));
                  
                  model->addRow(conn1);
                  model->addRow(conn2);
                  proxy->setSourceModel(model);
                  listWidget->setModel(proxy);
                  listWidget->setStyleSheet(
                        "QListView::item:selected {"
                        "border: 1px solid black;"
                        "border-radius: 3px;"
                        "color: black;"
                        "}"
                        );
                  listWidget->setItemDelegate(delegate);
                  

                  @

                  1 Reply Last reply
                  0
                  • raven-worxR Offline
                    raven-worxR Offline
                    raven-worx
                    Moderators
                    wrote on last edited by
                    #9

                    @listWidget->setItemDelegate(delegate);@
                    Whats the type of the delegate and what it's purpose?

                    Make sure it's of the type QStyledItemDelegate and of course don't override it's paint method. If you have to override the paint() method you also need to make sure that you paint the rounded border.

                    --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                    If you have a question please use the forum so others can benefit from the solution in the future

                    1 Reply Last reply
                    0
                    • T Offline
                      T Offline
                      tokafr
                      wrote on last edited by
                      #10

                      yes I paint the items, how can I paint rounded border when (the rect there is option.rect) and then fill the rounded border?
                      @
                      painter->drawRoundRect(option.rect);
                      painter->fillRect(option.rect, option.palette.highlight());
                      @

                      fills the default rectangle without rounded borders

                      1 Reply Last reply
                      0
                      • raven-worxR Offline
                        raven-worxR Offline
                        raven-worx
                        Moderators
                        wrote on last edited by
                        #11

                        Well you never said anything about it. Don't you think this would have been of any interest from the beginning?!!

                        drawRoundRect() is not a method of QPainter?!

                        "drawRoundedRect()":http://doc.qt.io/qt-5/qpainter.html#drawRoundedRect is and also has parameters to specify the border radius.

                        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                        If you have a question please use the forum so others can benefit from the solution in the future

                        1 Reply Last reply
                        0
                        • T Offline
                          T Offline
                          tokafr
                          wrote on last edited by
                          #12

                          Ok, I did it, thank you!! :)

                          1 Reply Last reply
                          0

                          • Login

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