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. QTextEdit and setStyle

QTextEdit and setStyle

Scheduled Pinned Locked Moved General and Desktop
20 Posts 3 Posters 12.2k 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
    GrahamL
    wrote on last edited by
    #3

    textEdit is of type QTextEdit not QTextLineEdit

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

      Just out of curiousity have you tried this:
      @
      textEdit->setStyleSheet("background-color: red);
      @

      and if that works fine try (of course your image file needs to be in the same dir as your sources then)
      @
      textEdit->setStyleSheet("background-image: url(Chrysanthemum.png); background-attachment: fixed");
      @

      if that works too I'd guess something is wrong with your way of setting the file location.

      1 Reply Last reply
      0
      • G Offline
        G Offline
        GrahamL
        wrote on last edited by
        #5

        Hi
        @textEdit->setStyleSheet("background-color: red);@
        works fine
        @edit->setStyleSheet("background-image: url(bg.png); background-attachment: fixed;");@
        Does not!
        What can be wrong

        1 Reply Last reply
        0
        • A Offline
          A Offline
          adnan
          wrote on last edited by
          #6

          It is working perfectly well on my computer:
          @ui->textEdit->setStyleSheet("background-image: url(:/nedge.png)");@

          Perhaps, you have not added your image to the resource file. Add "bg.png" to resource file and it should work.

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

            Thats very strange indeed, because an example from the "Qt Style Sheets Examples":http://qt-project.org/doc/qt-4.8/stylesheet-examples.html#customizing-specific-widgets is pretty much the same
            @
            QTextEdit, QListView {
            background-color: white;
            background-image: url(draft.png);
            background-attachment: fixed;
            }
            @

            My only guess is that somehow the file location is not correct. The bg.png file is located inside your source folder?

            1 Reply Last reply
            0
            • G Offline
              G Offline
              GrahamL
              wrote on last edited by
              #8

              OK
              Here is my complete code, the image bg.png exists in the directory where the app is being run but is not set as the background
              @#include <QtGui>

              int main(int argc, char **argv)
              {
              QApplication app(argc, argv);

               QTextEdit* edit = new QTextEdit();
               edit->setWindowTitle("QTextEdit Background Image");
               
               edit->setStyleSheet("background-image: url(bg.png)");
              
               edit->show();
               return app.exec();
              

              }@

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

                There is a mistake in the syntax:
                @edit->setStyleSheet("background-image: url(bg.png)");@

                It should be:
                @edit->setStyleSheet("background-image: url(:/bg.png)");@
                and "bg.png "must be" added to resource file and should in source directory

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  GrahamL
                  wrote on last edited by
                  #10

                  Hi
                  I still cannot get this working!
                  This is my .pro file
                  @TEMPLATE = app
                  TARGET =
                  DEPENDPATH += .
                  INCLUDEPATH += .

                  Input

                  SOURCES += main.cpp

                  RESOURCES +=
                  res.qrc
                  @
                  I used QCreator to add this image to the resource file
                  but still no joy

                  frustrated

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    adnan
                    wrote on last edited by
                    #11

                    I suppose there is only one way I can help you now. Make a zip file of your project and upload the download link so that i can download the project and look for the problem.

                    1 Reply Last reply
                    0
                    • G Offline
                      G Offline
                      GrahamL
                      wrote on last edited by
                      #12

                      Hi Adnam
                      Thanks for your help!
                      Forgive my ignorance (im new here) but how do I send you my project?

                      1 Reply Last reply
                      0
                      • A Offline
                        A Offline
                        adnan
                        wrote on last edited by
                        #13

                        I recieved your project , i will look into it

                        1 Reply Last reply
                        0
                        • G Offline
                          G Offline
                          GrahamL
                          wrote on last edited by
                          #14

                          Message sent

                          Thanks

                          1 Reply Last reply
                          0
                          • A Offline
                            A Offline
                            adnan
                            wrote on last edited by
                            #15

                            You had committed a silly mistake in adding the image to resource file. The prefix should had been "/" but it was "/images" in your case (it is also correct but) your folder containing the image was also named as "image", so the address of image should have been "/images/images/bn.jpg". It is working fine now. I have changed the prefix to "/" from "/images". So now the valid address is "/images/bn.jpg"

                            1 Reply Last reply
                            0
                            • G Offline
                              G Offline
                              GrahamL
                              wrote on last edited by
                              #16

                              Hi
                              Thanks, but it still does not work for me
                              There must be something different in our systems, but I dont know what!
                              do you have any ideas?

                              1 Reply Last reply
                              0
                              • A Offline
                                A Offline
                                adnan
                                wrote on last edited by
                                #17

                                As you said it is not working under windows but working under linux perhaps It’s the windows style that prevents it then.

                                1 Reply Last reply
                                0
                                • G Offline
                                  G Offline
                                  GrahamL
                                  wrote on last edited by
                                  #18

                                  I take it that you are using Linux then?

                                  1 Reply Last reply
                                  0
                                  • A Offline
                                    A Offline
                                    adnan
                                    wrote on last edited by
                                    #19

                                    Yes i use ubuntu

                                    1 Reply Last reply
                                    0
                                    • A Offline
                                      A Offline
                                      adnan
                                      wrote on last edited by
                                      #20

                                      I also have similar problems like GTK+ style of linux does not allow for changing background color of progress bar

                                      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