I wanted to provide a zooming effect to the images displayed in a ListView. Each time the list scrolls up & the item reaches top of my visible area. I want to zoom the image a little.
Is there any way to get that new full screen date picker with background blur (like in the image below) when tapping a custom button other than tapping the CompactDatePickerStyle() date picker?
I have a QTextEdit widget with a vertical scroll bar.
report_text = new QTextEdit();
report_text->setAcceptRichText(true);
report_text->setReadOnly(true);
report_text->setTextInteractionFlags(Qt::NoTextInteraction);
report_text->setAlignment(Qt::AlignTop);
report_text->setWordWrapMode(QTextOption::NoWrap);
report_text->setFrameStyle(QFrame::NoFrame);
report_text->setMinimumSize(600, 380);
report_text->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
This is Qt 4.8 embedded.
Now I need a method or an event I can send to the widget to make it it scroll up or down just as if the up or down buttons on the scroll bar had been pressed.
I tried the scroll() method, but I scrolls the whole widget, including the scroll bar.
I also tried sending a QWheelEvent, but nothing happens.
QWheelEvent ev(QPoint(), 10, 0, 0);
report_text->setFocus();
QApplication::sendEvent(report_text, &ev);
What am I missing?
It is probable that the delta you provided is just way too small.
From the documentation of QWheelEvent::delta():
Returns the distance that the wheel is rotated, in eighths of a
degree. A positive value indicates that the wheel was rotated forwards
away from the user; a negative value indicates that the wheel was
rotated backwards toward the user.
Most mouse types work in steps of 15 degrees, in which case the delta
value is a multiple of 120; i.e., 120 units * 1/8 = 15 degrees.
The text scrolling in Qt unit is the number of whole line. So if the widget computes that you want to scroll 0.9 lines, he might do nothing.
So try again with
QWheelEvent ev(QPoint(), 120, 0, 0);
Note: Nothing here apply to an event with control or shift modifier.
Here is what I found as a suitable solution:
The vertical scrollbar may be accessed using the QTextEdit::verticalScrollBar() method.
Scrollbars have a triggerAction() method to conveniently simulate user interaction with the buttons and the slider. The available actions are defined in QAbstractSlider.
So the resulting code is only a single line:
report_text->verticalScrollBar()->triggerAction(QAbstractSlider::SliderSingleStepAdd);
Interestingly, this works even when the scrollbar is hidden with
report_text->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
Could somebody tell me how to erase a rectangle that has just been drawn on an image?
In the application, I have an image displayed on a document (MDI application). The user can select a portion of the image. I implemented this feature as letting the user start the selection with a CRectTrackerColor (derived from CRectTracker) object. The selection works fine: a user is able select a rectangle using the mouse. A rubber band rectangle is shown as a feedback. After the user releases the left mouse, the rectangle is colored based on my pen color. Then I present a dialog for OK/Cancel. Upon Cancel, I would like the rectangle to disappear. How should I go about doing that?
Thanks.
Just invalidate that rectangle so it'll get redrawn normally.
How to enable horizontal scrollbar smooth scrolling for CGridCtrl. Now it jumps by fields when I scroll it from left to right.
I assume you're talking about CGridCtrl published in this CodeProject article.
If so, then you're going to have to completely override the drawing methods to offset the columns by the current scroll position (instead of calculating the first column to display from the scroll position).
To get you started, you should begin by looking at GetScrollPos(SB_HORZ) to use as an offset to begin drawing.