With Respect To ScrollBar To Rectangle
-
Hello Guys.
i have a rectangle, how to make rectangle width, height increase with respect to text ins side rectangle, as text increases, rectangle has to increase, and how to add scrollbar to rectangle as soon as text increases. please help me out.
-
@Pradeep-Kumar.M
i have a rectangle, how to make rectangle width, height increase with respect to text ins side rectangle, as text increases, rectangle has to increase
You can just simply bind the
pointSize
orpixelSize
ofText
to that ofRectangle
'swidth
andheight
with some multiplier.width: txtItm.font.pointSize * 10 height: txtItm.font.pointSize * 5
how to add scrollbar to rectangle as soon as text increases.
Rectangle
doesn't have a built-in scrollbar. You will need to create one yourself.
But I'm wondering what would you do by adding a Scrollbar to it.Rectangle
doesn't scroll. You need something likeFlickable
where in it would make sense. Example here.Also have a look at TextArea, it automatically adds Scrollbar when required.
-
thank you, because i want to have scrollbar to my rectangle as soon as text increases and i didnt make use modaldialog,or messagedialog. i made use of rectangle as messagedialog, i will try it.
-
and one more i have posted regarding listview, key up pressed and key down pressed
-
@Pradeep-Kumar.M
and one more thing i want to the difference between contentWidth, contentHeight, contentX, contentY.
i have a sample code, please look into it.
import QtQuick 2.4 import QtQuick.Window 2.2 Window { visible: true width: 300 height: 300 id:win Flickable { id: flick width: 80; height: 80 contentWidth: image.width contentHeight: image.height contentX: image.x contentY: image.y // contentY: 100 Image { id: image; width: 50 height: 50 x: 50 y: 100 source: "qrc:/new/prefix1/logo.png" } } }
-
@Pradeep-Kumar.M
x
andy
are for positions whilewidth
andheight
are for dimensions. -
@p3c0
import QtQuick 2.4
import QtQuick.Window 2.2Window {
id: win
visible: true
width: 700
height: 500
Rectangle
{
id: rect
width: t1.font.pixelSize * 50
height: t1.font.pixelSize * 10
color: "pink"
Text {
id: t1
text: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaajjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjaaaaaaaaaaa"
}
}
}as text size increases rectangle has to increase simultaneously , but in this case, its not increasing.
-
and one more thing it has to increase dynamically, with respect to text, please help.
-
@Pradeep-Kumar.M hmm you meant length not size. Well in that case you will need get text length and bind it with some multiplier.
Its better to use a TextArea here. Isn't it ? -
because data is coming from c++ class thats y, inserting it to rectangle directly . if so how to find text length, do we have length method for text, i didnt find it.
-
@Pradeep-Kumar.M Yes. Use
length
. -
thank u for example of scrollbar to rectangle, it worked, one issue in it is ,
when i drag down, scrollbar moving upwards, i dont want in that fashion, drag should be with respect to scrollbar, not opposite, please help me. -
@Pradeep-Kumar.M Must be some problem in your code. Try doing same as done in that example.
-
same thing i did it, will you please try, i want the scrollbar to have dragged with respect to mouse simulateonusly, not in opposite fashion, i tried,
-
@Pradeep-Kumar.M Can you explain it w.r.t to that example ? That example works fine as expected.
-
code is working fine, but the thing is scrollbar has to move w.r.t to mouse, when i want to scroll, for example in this forum if u want to scroll up, u will move your mouse up, w.r.t to scrollbar, but in the example case moving mouse upwards, scrolling takes place downwards, i mean to say opposite direction.
-
@Pradeep-Kumar.M Nope. If you scroll down the scrollbar moves down and ofcourse the image will go up and v.v. That's the intended behaviour.
-
hm k kk
-
and one more if we have implementation that works with keys press,
will it work for mouse area on clicked?. -
@Pradeep-Kumar.M Yes should work. Create a function and call that function when required.