快速控制2坏看

时间:2018-03-31 16:54:40

标签: qt qml qt5 qtquickcontrols2

Qt 5.10,Windows 10桌面。

以下QML代码:

import QtQuick 2.10
import QtQuick.Window 2.10
import QtQuick.Controls 2.3
import QtQuick.Layouts 1.3

Window {
    visible: true
    width: 250
    height: 100
    title: qsTr("My app")

    GridLayout
    {
        columns: 2

        Label {
            text: "Setting1:"
        }

        ComboBox {
            model: ["100%", "90%", "80%", "70%", "60%", "50%", "40%", "30%"]
        }

        CheckBox {
            id: tidle
            text: "Setting2:"
        }

        ComboBox {
            model: ["90%", "80%", "70%", "60%", "50%", "40%", "30%"]
            enabled: tidle.checked
        }
    }
}

给出以下结果:

enter image description here

对我来说非常糟糕:

1)"设置1"标签和复选框没有明显对齐。

2)与文本大小相比,Checkbox和ComboBox大小太大。

我是否会错过某些东西或它是正常行为?

1 个答案:

答案 0 :(得分:1)

这是正常行为。

Control具有以下布局:

enter image description here

例如Label的填充为0,另一方面CheckBox填充CheckBox { id: tidle text: "Setting2:" leftPadding: 0 } ,如果它们对齐,则有两种可能的解决方案:

  • 将CheckBox的leftPadding设置为0:
Label {
    text: "Setting1:"
    leftPadding : tidle.leftPadding
}

...

CheckBox {
    id: tidle
    text: "Setting2:"
}

enter image description here

  • 或者将Label设置为CheckBox的相同leftPadding:
Control

enter image description here

Qt提供以下指南来自定义ComboBox

对于import React from 'react' import { BrowserRouter as Router, Route } from 'react-router-dom' import { connect } from 'react-redux' import styles from './App.css' import { logout } from '../actions/user' import { userIsAuthenticatedRedir, userIsNotAuthenticatedRedir } from '../auth' import ProtectedComponent from './App.jsx' import LoginComponent from './Login.jsx' import Home from './Home' const Login = userIsNotAuthenticatedRedir(LoginComponent) const Protected = userIsAuthenticatedRedir(ProtectedComponent) function App({ user, logout }) { return ( <Router> <div className={styles.wrapper}> <div className={styles.content}> <Route exact path="/" component={Home}/> <Route exact path="/login" component={Login}/> <Route exact path="/app" component={Protected}/> </div> </div> </Router> ) } const mapStateToProps = state => ({ user: state.user }) export default connect(mapStateToProps, { logout })(App) 大小的情况,您可以使用FontMetrics来计算合适的大小,在我的情况下,我在Linux中并且没有必要。