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. Determining whether QLineEdit or QTextedit is used when string is edited in TableView

Determining whether QLineEdit or QTextedit is used when string is edited in TableView

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 1.5k 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.
  • G Offline
    G Offline
    gabor53
    wrote on last edited by
    #1

    Hi,
    I have a QItemEditorfactory set p the following way:

    QWidget *myDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
    {
        QItemEditorFactory *factory = new QItemEditorFactory;
        QItemEditorCreatorBase *lineEditor = new QStandardItemEditorCreator<QLineEdit>();
        factory->registerEditor (QVariant::String, lineEditor);
    }
    

    Is there a way to determine whether the string in the tableview to be handled by QLineEdit or QTextEdit?

    Thank you.

    jsulmJ 1 Reply Last reply
    0
    • G gabor53

      Hi,
      I have a QItemEditorfactory set p the following way:

      QWidget *myDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
      {
          QItemEditorFactory *factory = new QItemEditorFactory;
          QItemEditorCreatorBase *lineEditor = new QStandardItemEditorCreator<QLineEdit>();
          factory->registerEditor (QVariant::String, lineEditor);
      }
      

      Is there a way to determine whether the string in the tableview to be handled by QLineEdit or QTextEdit?

      Thank you.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @gabor53 How do you want to "determine" that? What are the criteria to decide? Can you explain better what you want to achieve?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      G 1 Reply Last reply
      0
      • jsulmJ jsulm

        @gabor53 How do you want to "determine" that? What are the criteria to decide? Can you explain better what you want to achieve?

        G Offline
        G Offline
        gabor53
        wrote on last edited by
        #3

        @jsulm
        Hi,
        I have fields where only short text is displayed like name or color. In these cases LineEdit is enough. I have bigger fields with several lines of text (like description) where TextEdit works better. My problem is that technically they are both string, just one of them usually longer than the other.

        jsulmJ 1 Reply Last reply
        0
        • G gabor53

          @jsulm
          Hi,
          I have fields where only short text is displayed like name or color. In these cases LineEdit is enough. I have bigger fields with several lines of text (like description) where TextEdit works better. My problem is that technically they are both string, just one of them usually longer than the other.

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @gabor53 Then you need to check the length of the string and if it exceeds a specific length then you use QTextEdit else QLineEdit.
          But actually it would be better to not to use the string length as it can change. Do you have any other information?

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          G 1 Reply Last reply
          0
          • jsulmJ jsulm

            @gabor53 Then you need to check the length of the string and if it exceeds a specific length then you use QTextEdit else QLineEdit.
            But actually it would be better to not to use the string length as it can change. Do you have any other information?

            G Offline
            G Offline
            gabor53
            wrote on last edited by
            #5

            @jsulm
            I can use the column title. I've just realized, that there are text fields where QComboBox would be the best as I can populate those from the database. I think the best way to determine the editor is using the column title, but I was told that was not the best idea.

            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