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. HTML inside QPushButton - how to insert images?
Forum Updated to NodeBB v4.3 + New Features

HTML inside QPushButton - how to insert images?

Scheduled Pinned Locked Moved General and Desktop
4 Posts 4 Posters 5.0k 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.
  • P Offline
    P Offline
    petwolf
    wrote on last edited by
    #1

    Hi all,

    I want to create Buttons similar to the ones here:
    !http://i42.tinypic.com/s64nqw.png(Copy Dialog)!

    I have found that the following code be used to format text in QPushButton - but I am not able to insert images into HTML code.

    @QPushButton *button = new QPushButton();
    QTextDocument Text;

    Text.setHtml("<h2><font color=white><font face=\"Segoe UI\">Close This App</font></h2>"
                 "<p>More Text</p>");
    
    QPixmap pixmap(Text.size().width(), Text.size().height());
    pixmap.fill( Qt::transparent );
    QPainter painter( &pixmap );
    Text.drawContents(&painter, pixmap.rect());
    
    QIcon ButtonIcon(pixmap);
    button->setIcon(ButtonIcon);
    button->setIconSize(pixmap.rect().size());@
    

    Could someone please help? TIA!

    Cheers
    Dee

    1 Reply Last reply
    0
    • R Offline
      R Offline
      Ruzik
      wrote on last edited by
      #2

      Try to create widget with your images, text and others and do that:
      @void yourWidget::paintEvent(QPaintEvent*)
      {
      QStylePainter painter(this);
      QStyleOptionButton option;

      option.initFrom(this);

      painter.drawControl(QStyle::CE_PushButton, option);
      }@
      I am not sure but it must work

      1 Reply Last reply
      0
      • G Offline
        G Offline
        goetz
        wrote on last edited by
        #3

        [[Doc:QCommandLinkButton]]s provides a look like that you want. The descriptive text is a plaintext and cannot take HTML/images, though.

        http://www.catb.org/~esr/faqs/smart-questions.html

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dscyw
          wrote on last edited by
          #4

          Got it.Thanks.

          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