Qt – die neusten Beiträge

Qt/QML Eine ScrollBar für ein TextField erstellen?

Hey,

ich möchte eine ScrollBar in Qt für ein TextField erstellen. Außerdem soll wenn man Text auswählt den man eingegeben hat und Rechts-Klick macht, ein Pop Up Menü angezeigt werden bei dem man Optionen wie z.B "Einfügen" oder "Kopieren" hat.

Wenn ich den Folgenden Code ausführe bekomme ich 2 Fehler:

  1. qrc:/main.qml:89:26: QML Rectangle: Binding loop detected for property "implicitWidth"
  2. qrc:/main.qml:89:26: QML Rectangle: Binding loop detected for property "implicitHeight"

Hier die main.qml:

import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 2.5

ApplicationWindow {
   id: mainWindow
   visible: true
   width: 900
   height: 600
   title: qsTr("Hello World")
    
    
   TextField {
       id: textFieldForURL
       width: parent.width/2
       height: parent.height/14
       y: parent.height/4
       x: -scrollBar1.position * width
    
       anchors.centerIn: parent
       leftPadding: 8
       topPadding: 4
       rightPadding: 43
    
       color: "white"
       font.pixelSize: parent.height/20
       selectionColor: "#3b3d45"
       placeholderText: "Type something"
       placeholderTextColor: "#3b3f44"
       selectByMouse: true
       maximumLength: 1000
  
       background: Rectangle {
          id: textFieldForURL_Background
          color: "black"
          radius: 5
  
          Rectangle {
             id: clearTextFieldForURL_Background
             width: parent.height
             height: parent.height
             anchors.right: parent.right
             color: "black"
          }
       }
  
      Text {
         id: clearTextFieldForURL
         height: parent.height
         width: parent.height
         text: "X"
         color: "white"
         font.pixelSize: 30
         anchors.right: parent.right
         leftPadding: 13
  
         MouseArea {
            id: clearTextFieldForURL_MouseArea
            height: textFieldForURL.height
            width: textFieldForURL.height
            hoverEnabled: true
            anchors.horizontalCenter: parent.horizontalCenter
            anchors.verticalCenter: parent.verticalCenter
  
            onClicked: {
               textFieldForURL.text = ""
               textFieldForURL.forceActiveFocus()
            }
            onEntered: {
               clearTextFieldForURL_Background.color = "#2a2c30"
            }
            onExited: {
               clearTextFieldForURL_Background.color = "black"
            }
         }
      }

      ScrollBar {
         id: scrollBar1
         hoverEnabled: true
         active: hovered || pressed
         orientation: Qt.Horizontal
         size: textFieldForURL_Background.width / textFieldForURL.width

         anchors.left: parent.left
         anchors.right: parent.right
         anchors.bottom: parent.bottom

         contentItem: Rectangle {
            implicitWidth: parent.width
            implicitHeight: parent.height
            radius: width / 2
            color: scrollBar1.pressed ? "white" : "#999999"
         }
      }
   }
}
Computer, Programm, programmieren, Programmiersprache, Qt, Scrollbar

Qt 5 Programm stürzt ab

Hi Leute ich wollte ein Test Programm programmieren.

Jetzt hab ich ein Problem und zwar mein Programm stürzt dauernd ab!

Hier sind die Codes(kdwindow.h):

#ifndef KDWINDOW_H
#define KDWINDOW_H
#include <QMainWindow>
#include <QPushButton>
#include <QLabel>
#include <QLayout>

namespace Ui {
    class KdWindow;
}

class KdWindow : public QMainWindow {
    Q_OBJECT

public:
    explicit KdWindow(QWidget *parent = 0);

private slots:
    void btnPressed();

private:
    QPushButton *btn;
    QLabel *label;

};


#endif // KDWINDOW_H

kdwindow.cpp:

#include "kdwindow.h"
#include <QCoreApplication>

KdWindow::KdWindow(QWidget *parent) : QMainWindow (parent) {
    label = new QLabel;
    label -> setText("Das ist ein einfacher Text");
    btn = new QPushButton("Klicken!", this);
    connect(btn, SIGNAL(clicked()), this, SLOT(btnPressed()));
    QVBoxLayout *vlayout = new QVBoxLayout;
    vlayout -> addWidget(label);
    vlayout -> addWidget(btn);
    setLayout(vlayout);
    setWindowTitle("KD Berechnung");
}

void KdWindow::btnPressed() {
    btn -> setText("Nochmal!");
}

und zu guter letzt die main.cpp:

#include "kdwindow.h"
#include <QApplication>

int main(int argc, char *argv[]) {
    QApplication app(argc, argv);
    KdWindow kdWindow;
    kdWindow.show();
    return app.exec();
}

Und die Fehler Meldung(naja mehr oder weniger):

Starte /Users/niklas/Documents/programming/Qt/build-KD-Desktop_Qt_5_4_0_clang_64bit-Debug/KD.app/Contents/MacOS/KD...
Das Programm ist abgestürzt.
/Users/niklas/Documents/programming/Qt/build-KD-Desktop_Qt_5_4_0_clang_64bit-Debug/KD.app/Contents/MacOS/KD ist abgestürzt
Programm, CPP, Qt, Absturz

Meistgelesene Beiträge zum Thema Qt