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. QT5.15.2 No background image from QPixmap
Forum Updated to NodeBB v4.3 + New Features

QT5.15.2 No background image from QPixmap

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 319 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.
  • T Offline
    T Offline
    TheoSys
    wrote on last edited by
    #1

    I have a couple of QLineEdit widgets and want to have a background image. I've found a lot of examples showing this with a CSS (setStylesheet()) method. In my case I can't use this method, because the image is drawn during run time. After the Image was drawn, I create a new QLineEdit and want the just drawn image as a background. But this seems not to work. Below is a simplified version of the code I use:

    [...]
        QLineEdit *linetext = new QLineEdit(button->getText().c_str(), parent);
        linetext->setFixedSize(button->getWidth(), button->getHeight());
        linetext->move(button->getLeftPosition(), button->getTopPosition());
        linetext->setFrame(false);
        Button::BITMAP_t bm = button->getLastImage();
    
        QPixmap pix(bm.width, bm.height);
        QImage img(bm.buffer, bm.width, bm.height, QImage::Format_ARGB32);
        pix.convertFromImage(img);
    
        QPalette palette;
        palette.setBrush(QPalette::Base, QBrush(pix));
    //    palette.setBrush(QPalette::Window, QBrush(pix));    // <-- doesn't work either
        linetext->setPalette(palette);
       obj->object.linetext->show();
    [...]
    

    Is there a way to get the image to the background of QLineEdit? What is wrong with my code?
    The above method work fine with QLabel.

    In case you're interested in the whole code (huge!) you can download the open source version with svn:

    svn co https://www.theosys.at/svn/tpanel
    

    The part in question is in file tqtmain.cpp starting at line 1378 (method MainWindow::inputText(Button::TButton* button)). The code compiles on Linux and for Android. You need, beside QT, the Skia library (https://skia.org/docs/user/download) to compile the code.

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

      Hi

      I think it's maybe the picture itself as

        QPalette palette;
          QPixmap pix(":/abstract-geometric-pattern-lines-rhombuses-260nw-573952828.jpg");
          palette.setBrush(QPalette::Base, QBrush(pix));
          ui->lineEdit_2->setPalette(palette);
      

      alt text

      just worked.

      try save it to a file and see if its valid.

      1 Reply Last reply
      0
      • T Offline
        T Offline
        TheoSys
        wrote on last edited by
        #3

        Thanks for your reply. The tip to save the graphic into a file helped me a lot because I saw, that I get what I see. The 'setBrush()' function works and shows my graphic.

        A.T.

        1 Reply Last reply
        1

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved