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. Styling QComboBox's lineedit
Forum Updated to NodeBB v4.3 + New Features

Styling QComboBox's lineedit

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 1.8k 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.
  • V Offline
    V Offline
    voltron
    wrote on last edited by
    #1

    I have a QComboBox subclass where custom lineedit is used like this

    QLineEdit *lineEdit = new QLineEdit(this);
    lineEdit->setReadOnly(true);
    setLineEdit(lineEdit);
    

    As result combobox looks like editable combobox
    custom combobox
    Is it possible to style lineedit or my custom combobox as whole so it looks like standard QComboBox?
    standard combobox

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      hi

      alt text

      alt text

      But why you set a read-only QLineEdit when QComboxBox allows this with the "Editable" property?

      Or you have other reason besides being readOnly ?

      V 1 Reply Last reply
      1
      • mrjjM mrjj

        hi

        alt text

        alt text

        But why you set a read-only QLineEdit when QComboxBox allows this with the "Editable" property?

        Or you have other reason besides being readOnly ?

        V Offline
        V Offline
        voltron
        wrote on last edited by
        #3

        @mrjj Thanks for fixing images.

        I want to style lineedit (second image in your post) to get same look and feel as standard QCombobox provides (first image in your post). Is this possible?

        mrjjM 1 Reply Last reply
        0
        • V voltron

          @mrjj Thanks for fixing images.

          I want to style lineedit (second image in your post) to get same look and feel as standard QCombobox provides (first image in your post). Is this possible?

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @voltron
          Hi
          Are you sure you need that?
          You assign a new lineEdit to set it to read-only.

          You can actually do that without setting it manually

          alt text

          In any case to style pic 2 to look like pic 1
          is not super trivial as you have to recreate the dropdown arrow as it reset as soon as you apply stylesheet.
          So you would have to use image for that to make it look right.

          alt text

          https://doc.qt.io/archives/qt-4.8/stylesheet-examples.html#customizing-qcombobox

          V 1 Reply Last reply
          0
          • mrjjM mrjj

            @voltron
            Hi
            Are you sure you need that?
            You assign a new lineEdit to set it to read-only.

            You can actually do that without setting it manually

            alt text

            In any case to style pic 2 to look like pic 1
            is not super trivial as you have to recreate the dropdown arrow as it reset as soon as you apply stylesheet.
            So you would have to use image for that to make it look right.

            alt text

            https://doc.qt.io/archives/qt-4.8/stylesheet-examples.html#customizing-qcombobox

            V Offline
            V Offline
            voltron
            wrote on last edited by
            #5

            Are you sure you need that?

            Absolutely. I know why and what I do here, if using standard combobox was possible I definitely would use it.

            Probably my question was formulated not very clear. When using CSS I can not maintain style changes like Fusion, Windows... and can not easily support themes. Also this way 3D bevel and shadow effects are not available.

            BTW, to apply color there is much simpler way

            QPalette palette = qApp->palette();
            palette.setBrush(QPalette.Base, palette.button());
            lineEdit->setPalette(palette);
            

            The only missed bit is a pseudo 3D appearance.

            1 Reply Last reply
            0
            • mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by mrjj
              #6

              Hi
              Ok just asking as making the editing part of a combobox read-only is directly supported.

              I understand the issue using stylesheets since its then not following the platform look.

              Im not sure how one would style it to look like the
              normal combo with noedit.

              I think with some fiddling you can use a ProxyStyle
              to only paint the text on top but since you dont want the
              look from having "editable" disabled im not sure what you are after.

              On windows, this looks like the NoEdit version

               {
                      QLineEdit *lineEdit = new QLineEdit(this);
                      lineEdit->setReadOnly(true);
                      lineEdit->setStyleSheet("background-color:transparent");
                      setLineEdit(lineEdit);
                  }
              

              But I guess on your platform, it still dont look right.

              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