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 to make QLabel text selectble in QStyledItemDelegate type of class
Qt 6.11 is out! See what's new in the release blog

How to make QLabel text selectble in QStyledItemDelegate type of class

Scheduled Pinned Locked Moved General and Desktop
15 Posts 5 Posters 12.0k 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.
  • G Offline
    G Offline
    goetz
    wrote on last edited by
    #4

    Unfortunately, I don't have any solution for this at all, not even for using that functionality outside of a list/tree view.

    http://www.catb.org/~esr/faqs/smart-questions.html

    1 Reply Last reply
    0
    • U Offline
      U Offline
      umen242
      wrote on last edited by
      #5

      Thanks for the help , still looking for solution ...

      1 Reply Last reply
      0
      • S Offline
        S Offline
        stima_ua
        wrote on last edited by
        #6

        @
        pseudo code


        class QModelIndex;

        IView {
        public:
        virtual void setSelected(const QModelIndex& index, bool flag) = 0;
        }

        MyListView : public QListView, public IView {
        ItemDelegate *delegate;

        public:
            MyListView(QWidget *parent = 0) : QListView(parent)
            {
                 delegate = new ItemDelegate;
                 delegate->setView(this);
        
                setItemDelegate(delegate);
            }
         
        void setSelected(const QModelIndex& index, bool flag) {
               QListWidgetItem *item = item(index.row());
               MyWidget *w = static_cast<MyWidget*>(itemWidget(item));
        
              w->setSelected(flag);
        }
        

        }

        void ItemDelegate::setView(IView *view)
        {
        this->view = view; //pimpl
        }

        void ItemDelegate::paint (QPainter* p, const QStyleOptionViewIte& o, const QModelIndex& i) const
        {
        QStyleOptionViewItemV4 option = o;

        initStyleOption(&option, i);
        
        bool selected = ( option.state &  QStyle::State_Selected );
        view->setSelected(i, selected);
        

        QSyledItemDelegate::paint(p, o, i);
        }
        @

        1 Reply Last reply
        0
        • K Offline
          K Offline
          KA51O
          wrote on last edited by
          #7

          How about using a lineEdit or something like this (some kind of text editor widget) and set the image containing the information you additionally want to display as the background of that text editor field?

          1 Reply Last reply
          0
          • U Offline
            U Offline
            umen242
            wrote on last edited by
            #8

            i have no problem , i just need to see how to do it right .. some start point

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #9

              I gather you need to have text selectable for a read-only table, right?

              So... what you could try, is to set QLabel as your 'editor' by using a custom delegate or by using a class like [[doc:QItemEditorCreator]] or [[doc:QStandardItemEditorCreator]]. Then, you could use a [[doc:QIdentityProxyModel]] to make the cells in your table writable again. That way, when you click a table cell, the editor will be used. However, in this case the editor will be a QLabel: still not editable, but selectable nontheless.

              1 Reply Last reply
              0
              • U Offline
                U Offline
                umen242
                wrote on last edited by
                #10

                Hi and thanks for the replay ,
                im using ListView , and the selectable text is part of the item delegate
                in this item there will be also images. its not a table.

                1 Reply Last reply
                0
                • U Offline
                  U Offline
                  umen242
                  wrote on last edited by
                  #11

                  Ok i found great solution , i really what you to say what you think ,
                  after looking at the code of "QTwitter":http://qt-apps.org/content/show.php/qTwitter?content=99087 , i saw it uses custom widget as the item
                  i mean widget that made in the Q Designer .

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    andre
                    wrote on last edited by
                    #12

                    If you are after a list-based UI like that, I would suggest looking into embedding a QML-based listview in your application.

                    1 Reply Last reply
                    0
                    • U Offline
                      U Offline
                      umen242
                      wrote on last edited by
                      #13

                      Hi thanks for the replay , yes i do look after list based look.
                      I will look into QML .
                      can you give me your opinion about the solution used in the QTwitter ?

                      1 Reply Last reply
                      0
                      • A Offline
                        A Offline
                        andre
                        wrote on last edited by
                        #14

                        Sorry, I have no time to dig through its code right now, and I can't judge only based on screenshots.
                        Just using a widget for every item in the model would not be performant for larger models. No idea if that is the approach taken though.

                        1 Reply Last reply
                        0
                        • U Offline
                          U Offline
                          umen242
                          wrote on last edited by
                          #15

                          thanks again for your opinion , its not large list its like 30 items in first in last out kind of way .

                          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