maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Applications (https://talk.maemo.org/forumdisplay.php?f=41)
-   -   How do I make a scrollable gui with QtCreator? (https://talk.maemo.org/showthread.php?t=72766)

azkay 2011-05-04 01:36

How do I make a scrollable gui with QtCreator?
 
Ive looked through;
http://wiki.maemo.org/Qt4_Hildon_Leg...etic_scrolling
http://doc.qt.nokia.com/qt-maemo-4.6...tml#setEnabled
http://doc.qt.nokia.com/qt-maemo-4.6...-textedit.html

I still cant get a scrollable gui working.
Basically, im trying to make a QScrollArea and be able to, well, kinetic scrolling.

I plan on have lots of text labels and images, I am wanting to be able to scroll down the GUI to be able to read them.

Anyone got an example?

gionni88 2011-05-04 07:03

Re: How do I make a scrollable gui with QtCreator?
 
If you're using QtDesigner, right click inside the QScrollArea and pick a layout, than you can start adding your labels.

If the scroll area is a lot bigger, than expand your main window to the bottom and make a QWidget where you place all your objects, than in the MainWindow constructor set this widget inside the scrollArea: ui->scrollArea->setWidget(ui->widget);

azkay 2011-05-04 11:05

Re: How do I make a scrollable gui with QtCreator?
 
Thanks, I dont know how I missed that.

pichlo 2014-07-16 20:51

Re: How do I make a scrollable gui with QtCreator?
 
Is reviving a 3yo thread better or worse than creating a new one? :)

Anyway, I have a QScrollArea that covers most of the screen. Inside it, I have a widget of type Preview, derived from QGLWidget.

I also have zoom buttons. Zoom affects the horizontal size only, the vertical dimension is fixed. The problem is that zooming in more than two times segfaults the program.

Here is the relevant bit where it segfaults:
Code:

void Preview::paintGL ()
{
  QPainter painter(this);
  painter.setRenderHint(QPainter::Antialiasing, true);

  const int w = width();
  const int h = height();

  // Paint the background
  painter.fillRect(0, 0, w, h, Qt::white);

  // ... a few dozen more lines ...

  painter.end();
}

It crashes on the painter.fillRect line, as verified by sticking qDebug before and after. Values of w and h were:

w=668, h=416, OK (starting point)
w=1002, h=416, OK (zoom in x1)
w=1503, h=416, OK (zoom in x2)
w=2254, h=416, crash!

What is going on? Can the device not handle painting areas of that size? (Code written, built and run entirely on the phone.)

Given the experience, I am inclined to rewrite the code to eliminate QScrollArea altogether and instead do my own redrawing the preview with moving starting point. What options do I have to drag the picture left or right with the finger? I would really prefer not to try implementing my own version of kinetic scrolling if I can.

jackburton 2014-07-16 21:15

Re: How do I make a scrollable gui with QtCreator?
 
Quote:

Originally Posted by pichlo (Post 1433055)
Is reviving a 3yo thread better or worse than creating a new one? :)

Anyway, I have a QScrollArea that covers most of the screen. Inside it, I have a widget of type Preview, derived from QGLWidget.

I also have zoom buttons. Zoom affects the horizontal size only, the vertical dimension is fixed. The problem is that zooming in more than two times segfaults the program.

Here is the relevant bit where it segfaults:
Code:

void Preview::paintGL ()
{
  QPainter painter(this);
  painter.setRenderHint(QPainter::Antialiasing, true);

  const int w = width();
  const int h = height();

  // Paint the background
  painter.fillRect(0, 0, w, h, Qt::white);

  // ... a few dozen more lines ...

  painter.end();
}

It crashes on the painter.fillRect line, as verified by sticking qDebug before and after. Values of w and h were:

w=668, h=416, OK (starting point)
w=1002, h=416, OK (zoom in x1)
w=1503, h=416, OK (zoom in x2)
w=2254, h=416, crash!

What is going on? Can the device not handle painting areas of that size? (Code written, built and run entirely on the phone.)

Given the experience, I am inclined to rewrite the code to eliminate QScrollArea altogether and instead do my own redrawing the preview with moving starting point. What options do I have to drag the picture left or right with the finger? I would really prefer not to try implementing my own version of kinetic scrolling if I can.

Interesting problem. I haven't done Qt in a while. Do you have any source to test with? Is this Maemo 5?

You may also find hints in the Qalendar source code. The author does a lot of his own drawing in there. Very clean code.

marxian 2014-07-16 21:16

Re: How do I make a scrollable gui with QtCreator?
 
I did a simple test using a QScrollArea and a plain QWidget, and was able to continue expanding the size of the widget without any problem:

http://t.imgbox.com/Pu1qY7vF.jpg

Perhaps you could try substituting the QGLWidget for a QWidget to see if the problem is related to QGLWidget.

It might also be worth showing the setup code for the QScrollArea and child widget (do you have 'widgetResizable' enabled and so on).

pichlo 2014-07-16 21:44

Re: How do I make a scrollable gui with QtCreator?
 
Here are the initializing bits:

1) mainwindow.ui (relevant part only)
Code:

      <item>
      <widget class="QScrollArea" name="scrollArea">
        <property name="widgetResizable">
        <bool>true</bool>
        </property>
      </widget>
      </item>

2) mainwindow.h (simplified)
Code:

#include "stackedmainwindow.h"
#include "ui_mainwindow.h"
#include "preview.h"

class MainWindow : public StackedMainWindow
{
  Q_OBJECT

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

private slots:
  void on_buttonZoomHome_clicked ();
  void on_buttonZoomIn_clicked ();
  void on_buttonZoomOut_clicked ();

private:
  Ui::MainWindow ui;
  Preview preview;
  double scaleFactor;
};

3) mainwindow.cpp (simplified)
Code:

MainWindow::MainWindow (QWidget *parent)
  : StackedMainWindow(parent)
  , preview(this)
  , scaleFactor(1.0)
{
  ui.setupUi(this);
  ui.scrollArea->setWidget(&preview);
}

I will try replacing QGLWidget with QWidget. It might be a QGLWidget problem after all, not QScrollArea one. In the meantime, I made another experiment with the only thing changed is reducing the scale factor from 1.5 to 1.25. The result...

w=668, h=424
w=835, h=416
w=1043, h=416
w=1043, h=416
w=1304, h=416
w=1630, h=416
w=2038, h=416
w=2548, h=416, crash!

So it does seem to be size related.

Copernicus 2014-07-16 22:38

Re: How do I make a scrollable gui with QtCreator?
 
Another item to test: you could try just placing the Preview widget directly into the UI without embedding it within a QScrollArea widget. I kind of get the feeling that if this is a memory overrun or a clipping error, it'd be more likely to happen closer to the widget with the actual image data. I kind of doubt that QScrollArea would be so sensitive to the physical size of the image...

BTW, on kinetic scrolling: it seems you can enable kinetic scrolling on most any Qt Maemo widget that can scroll. You can manipulate this feature (turning it on or off, retrieving various scrolling info, or messing around with it in general) by accessing the "kineticScroller" property of the widget. For example, this would switch on kinetic scrolling for a widget called "scrollArea":

Code:

QAbstractKineticScroller *scroller = scrollArea->property("kineticScroller").value<QAbstractKineticScroller *>();

 if (scroller)
    scroller->setEnabled(true);

There's a bunch more info in the Qt docs about this. :)

marxian 2014-07-16 22:52

Re: How do I make a scrollable gui with QtCreator?
 
Quote:

Originally Posted by Copernicus (Post 1433072)
BTW, on kinetic scrolling: it seems you can enable kinetic scrolling on most any Qt Maemo widget that can scroll.

I think the only widgets that can scroll are those derived from QAbstractScrollArea (QScrollArea and the item views/widgets) and QWebView. Those are the only widgets I know of that have a QAbstractKineticScroller.

jflatt 2014-07-16 23:09

Re: How do I make a scrollable gui with QtCreator?
 
Max texture size and max render buffer on SGX 530 is 2048x2048

pichlo 2014-07-16 23:45

Re: How do I make a scrollable gui with QtCreator?
 
Quote:

Originally Posted by jflatt (Post 1433074)
Max texture size and max render buffer on SGX 530 is 2048x2048

Thanks. I was suspecting something like that. Can you provide a chapter and verse, please? I was looking for that but could not find it. Also, pardon my ignorance, but what is SGX 530? ;)

Edit: Never mind, I found it. Thanks again!

Hariainm 2014-07-17 00:05

Re: How do I make a scrollable gui with QtCreator?
 
Quote:

Originally Posted by pichlo (Post 1433076)
Thanks. I was suspecting something like that. Can you provide a chapter and verse, please? I was looking for that but could not find it. Also, pardon my ignorance, but what is SGX 530? ;)

PowerVR SGX530 is the GPU present in Nokia N900 & N9.

pichlo 2014-07-17 00:39

Re: How do I make a scrollable gui with QtCreator?
 
OK, case closed, thanks to all who replied. FYI, the problem was QGLWidget. Replacing it with QWidget not only solved the problem but also made the redrawing much faster. The program also starts faster and is a bit smaller. All win, no lose.

marxian 2014-07-17 00:46

Re: How do I make a scrollable gui with QtCreator?
 
Quote:

Originally Posted by pichlo (Post 1433080)
OK, case closed, thanks to all who replied. FYI, the problem was QGLWidget. Replacing it with QWidget not only solved the problem but also made the redrawing much faster. The program also starts faster and is a bit smaller. All win, no lose.

Yeah, I was going to ask if you were using QGLWidget for performance reasons (hardware acceleration). I have found in the past that using a QGLWidget for the viewport when rendering QGraphicsItems on the N900 is actually slower than using a plain QWidget.

pichlo 2014-10-18 21:38

Re: How do I make a scrollable gui with QtCreator?
 
To continue with silly questions, I have a need to scroll an area only a few hundred pixels high but potentially a hundred million or more pixels wide. Has anyone tried that? I've only gone as high as a couple million and my device rebooted while initializing the area. Presumably the damn watchdog again. Any idea how to implement kinetic scrolling myself?

coderus 2014-10-18 21:44

Re: How do I make a scrollable gui with QtCreator?
 
implement dynamic buffering yourself

Estel 2014-10-19 11:22

Re: How do I make a scrollable gui with QtCreator?
 
Quote:

Originally Posted by pichlo (Post 1443412)
To continue with silly questions, I have a need to scroll an area only a few hundred pixels high but potentially a hundred million or more pixels wide.

Out of curiosity, what is it? The hundred millions pixels wide thing?

pichlo 2014-10-20 08:36

Re: How do I make a scrollable gui with QtCreator?
 
@coderus, that's what I kinda hoped to avoid. Doing that, I may as well implement the whole thing myself. Which I may have to do anyway since I need the vertical scroll bar on the left and for the life of me can't figure out how to persuade stock QScrollArea to do that.

@Estel, can you think of any application when you may need to plot a long graph with a narrow vertical range?

coderus 2014-10-20 08:42

Re: How do I make a scrollable gui with QtCreator?
 
@pichlo you need dynamic plotting indeed. Drawing whole thing and keeping it in memory in some "scrollable" is VERY bad idea ;)

MartinK 2014-10-20 13:10

Re: How do I make a scrollable gui with QtCreator?
 
The QtQuick 2.0 Canvas supports tiled rendering - maybe check how it is implemented (I looked at its source and it is quite readable :) ) for inspiration ? :)

pichlo 2014-10-20 17:39

Re: How do I make a scrollable gui with QtCreator?
 
Quote:

Originally Posted by coderus (Post 1443503)
@pichlo you need dynamic plotting indeed. Drawing whole thing and keeping it in memory in some "scrollable" is VERY bad idea ;)

That's kinda obvious. I was (foolishly) assuming that QScrollArea was a bit smarter than that: provite some framework for scrolling but let the widget draw itself. For example my widget draws only the part that needs updating and is never wider than the screen. But it seems that QScrollArea caches the whole million pixèls, even though most of them are empty.


All times are GMT. The time now is 21:28.

vBulletin® Version 3.8.8