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. [Solved] How to get a QTableView with a text and a delegate in the same cell?
QtWS25 Last Chance

[Solved] How to get a QTableView with a text and a delegate in the same cell?

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 4.4k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    Hello guys:

    I've a QTableVew working fine with a QAbstractTableModel subclass and a QItemDelegate subclass. I would like to know if there is a way to get a delegate sharing the same cell with a text. For example:

    Lets say I've a column named Proxy and I want the cells have the following format:

    192.168.0.1:3128

    ...where the ip address is a text (maybe a QLineEdit) and the port is a QSpinBox, and they are in the same cell.

    I've made some test but I didn't get it working.

    ...some suggestions?

    Thanks in advance.

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

      A delegate does not occupy a cell, it is responsible for both painting a cell and handing interaction with one. That also means that you cannot "share" the space in a cell between a delegate and a text, as a delegate is responsible for rendering that text in the first place. If you did not set a delegate, then Qt is using the default one.

      So, if you want a delegate that renders both a text and something else, you will have to create that.

      From your text, it is not clear if you want to have your line edit and your spinbox always visible, or just when editing. I would suggest the later. In that case, the easiest solution is to create a widget that combines a QLabel, a QLineEdit and a QSpinBox in a horizontal layout, and use that as the editor widget for your delegate.

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        Yes, I prefer to show the widget just when editing the cell.

        What I don't understand is, why I need a QLabel and a QLineEdit in the widget I have to create? I believe the QLineEdit together with the QSpinBox could be enough, isn't?

        Anyway, I will do it as you suggested, it seems to be logical, and maybe the only way or at less the simplest. In fact during my tests I had some similar idea, now I understand why it doesn't worked.

        Thanks for your quick answer and the technical correction.

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

          I guess it depends how you want your editor to look exactly. I was under the impression you had some text there that was not directly editable (you talked about sharing the space between the rendered text and an (editable?) delegate), but perhaps I just misunderstood. If you don't need the static text while editing, then you just leave out the label.

          Glad to help, I hope it works out well for you!

          1 Reply Last reply
          0
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #5

            Sorry for the misunderstanding. What I meant was a text that could be edited when editing the cell, that was the reason what I mentioned to use QLineEdit instead of QLabel.

            But what surely was very clear, was your advice. I got it working exactly as you suggested.

            Thanks again for your help.

            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