Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Custom Button containing Image and Text
Forum Updated to NodeBB v4.3 + New Features

Custom Button containing Image and Text

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 3 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.
  • M Offline
    M Offline
    maxoox
    wrote on 3 Jan 2018, 10:10 last edited by
    #1

    Hello,

    I'm creating my first application with QML and I'm also new to Qt at all :)

    I like to create buttons that are similar to QtCreators (left) sidebar buttons (Welcome, Edit, Design etc): So that they consist of an icon and a label. As far as i 'researched' at various sources in the internet there are a few approaches. In the main.qml i like to use the following structure (is that ok?):

    // main.qml
    
    //..
    GroupBox {
       /* some properties */
        ButtonGroup {
            buttons: mainButtons.children
        }
        Column {
             id: mainButtons
             CustomButton {
                 id: btn1
             }
             CustomButton {
                 id: btn2
             }
        }
    }
    //..
    

    My first try was declaring a CustomButton like:

    // CustomButton.qml
    import QtQuick 2.0
    import QtQuick.Controls 2.2
    import QtQuick.Controls.Material 2.2
    
    Button {
        width: ...
    }
    

    But including an icon seems impossible to me. I also saw the CustomButton Example at Qt's website, but why use 'Item' and so on for declaring a button, as long as there's a separate 'Button' item?

    This looks really confusing to me. In addition to that: Is there a common way / structure of storing images in the resource folder? I like to use *.svg files (Material Design Icons by Google), but i read that *.png files are recommended.

    So there's a lot to cover here, but i think it's all in the context of creating custom buttons in a recommended way.

    Thanks!

    1 Reply Last reply
    1
    • O Offline
      O Offline
      ODБOï
      wrote on 3 Jan 2018, 10:28 last edited by
      #2

      Hello,
      see this : http://doc.qt.io/qt-5.10/qml-qtquick-controls2-button.html & http://doc.qt.io/qt-5.10/qml-qtquick-controls2-abstractbutton.html if you want to customize QML Button Type,

      or you can create your own Btn

      Rectangle{
       Image{
      ...
      }
      Text{
      ...
      }
      MouseArea{
      ...
      }
      }
      

      LA

      1 Reply Last reply
      3
      • J Offline
        J Offline
        jpnurmi
        wrote on 3 Jan 2018, 14:20 last edited by
        #3

        Qt Quick Controls 2.3 (Qt 5.10) has added support for icons in Buttons and Actions: http://doc.qt.io/qt-5.10/qtquickcontrols2-icons.html

        1 Reply Last reply
        1

        1/3

        3 Jan 2018, 10:10

        • Login

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