Focus not seen in Qt for Qdial subclass - c++

I am using Qt in Visual Studio to get an interface with buttons and knobs etc. I am using this SkinnedDial class - http://dronecolony.com/2012/12/11/customized-qdial-with-qss-support/ , to get a QDial with a custom image. But the problem is that while the other controls are showing the focus frame when I tab over them, this control does not show the focus - for instance button shows the rectangle, but nothing shows up for the dial. Here's the code segment for the dial -
SkinnedDial *myDial;
...
myDial = new SkinnedDial(this);
myDial->setRange(-100, 100);
QPixmap *bg = new QPixmap();
bg->load("C:/Current/dial.png");
QPixmap *nl = new QPixmap();
nl->load("C:/Current/needl.png");
myDial->setBackgroundImage(*bg);
myDial->setNeedleImage(*nl);
myDial->setMaxAngle(100);
I am new to Qt and C++ and I'm not sure how to solve this problem.

Related

QT ScrollBars doesn't appear with scrollAreaWidgetContents

I am trying to learn QT with visual studio. My development environment is VS2015 with QT designer. I am trying to do the following tutorial.
http://www.bogotobogo.com/Qt/Qt5_QMainWindow_QAction_ImageViewer_B.php
essentially the tutorial displays an image with Qlabel and QScrollArea. If I create the widgets with code (using visual studio) the program seems to work.
imageLabel = new QLabel;
imageLabel->setBackgroundRole(QPalette::Base);
imageLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
imageLabel->setScaledContents(true);
scrollArea = new QScrollArea;
scrollArea->setBackgroundRole(QPalette::Dark);
scrollArea->setWidget(imageLabel);
setCentralWidget(scrollArea);
However, then I tried to do the same with QT Designer. When I dragged a ScrollArea from QT Designer, I notices that it also created a QWidget called "scrollAreaWidgetContents". Then when I created the QLabel, Label was created under "scrollAreaWidgetContents" widget. I then tried to display the image using the following code.
ui->label->setBackgroundRole(QPalette::Base);
ui->label->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
ui->label->setScaledContents(true);
ui->scrollArea->setBackgroundRole(QPalette::Dark);
ui->scrollArea->setWidget(ui->scrollAreaWidgetContents);
ui->scrollArea->setWidgetResizable(true);
ui->scrollAreaWidgetContents->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
//ui->scrollArea->setWidget(ui->label);
setCentralWidget(ui->scrollArea);
The problem with this is that the scroll Bars never appears. See the attached
Then I uncommented "ui->scrollArea->setWidget(ui->label);" line and then the program compiles but crashes. So, how do I make the scrollBars appear with QT Designer? What am I doing wrong.
Thanks for the help

Qt GUI C++ (Android) - How to scroll outside the scroll area without touching the scroll bar?

How can I scroll even when not touching the scroll bar inside the scroll area? Im developing an app for android using Qt widgets Application. Thank you for your response.
Qt 5.6.0.
In case the link becomes invalid:
The QScroller object is the object that stores the current position and scrolling speed and takes care of updates. QScroller can be triggered by a flick gesture
QWidget *w = ...;
QScroller::grabGesture(w, QScroller::LeftMouseButtonGesture);
or directly like this:
QWidget *w = ...;
QScroller *scroller = QScroller::scroller(w);
scroller->scrollTo(QPointF(100, 100));

QGraphicsView rendering its sub widget's sub widget weirdly

I'm working on a music/MIDI editor using C++ and Qt.
The develop was smooth until I met an issue that QGraphicsView is rendering weirdly with its child widget's child widget.
(wow, that's confusing)
This is the code I used to add my sub widgets to a QGraphicsView
pianoPlain = new QawPianoPlain();
keyBoard = new QawPianoKeyBoard();
scene->addWidget(pianoPlain);
scene->addWidget(keyBoard);
keyBoard->setGeometry(0,0,100,540);
keyBoard->setKeyNum(36);
pianoPlain->setGeometry(100,0,500,540);
pianoPlain->setStriptNum(36);
The code makes something like this.
pianoRoll -> keyBoard -> key
...............|-> pianoPlaom -> noteStript
Where pianoPlain and keyBoard are classes I inherit from GraphicsView and key and noteStript are both inherit from QWidget.
Here is a picture of what happens:
https://drive.google.com/file/d/0BzYLJIsbhhuVZ0RMdzRqV01Cd2M/view?usp=sharing
And this is picture of a normal keyBoard which is placed directy in MainWindow(left) and a screwed up one placed in QGraphicsView(right)
(I have disable back/while key in this picture)
https://drive.google.com/file/d/0BzYLJIsbhhuVSDFhSXRVM0dHWnM/view?usp=sharing
It seems that whenever pianoPlain and keyBoard are placed in a QGtraphicsView, it will be screwed.
Anyone know what's happening? How can I fix this?
Qt : 5.4.1
OS : KUubutu 15.04 AMD64
Compiler : clang 3.6.0/ GCC 4.9.2
I would suggest pianoPlain and keyBoard should use a class that inherits QGraphicsItem - for example QGraphicsPixmapItem or QGraphicsProxyWidget.
You then would add these to the scene using your scene->addWidget() method.
The scene itself should then be part of a QGraphicsView.
For example:
QGraphicsView *view = new QGraphicsView();
QGraphicsScene* scene = new QGraphicsScene(view);
view->setScene(scene_);
// No need to parent these
pianoPlain = new QawPianoPlain();
keyBoard = new QawPianoKeyBoard();
// This will work if QawPianoPlain and QawPianoKeyBoard inherit QWidget
QGraphicsProxyWidget* pianoProxy = scene_->addWidget(pianoPlain);
QGraphicsProxyWidget* keyBoardProxy = scene_->addWidget(keyBoard );
Use the proxy widget for any transformations/animations.

QQuiickWidgets within TabWidgets crashes when rendering OpenGL code

QQuickWidgets embedded in QTabWidget container, crashes upon rendering custom OpenGL code, via QML, QQuickItem and QSGNode.
The crash or scene flickering happens when you click on the other tabs on the QTabWidget and return back to the rendering tab.
QQuickWidget* m_quickWidget = new QQuickWidget;
QTabWidget *tabs = new QTabWidget(this);
tabs->addTab(m_quickWidget,"TAB Rendering");
tabs->addTab(new QWidget(),"TAB 1");
m_quickWidget->setResizeMode(QQuickWidget::SizeRootObjectToView );
m_quickWidget->setSource(source);
setCentralWidget(tabs);
The above scenario runs peacefully without any problem when using QQuickViews:
QTabWidget *tabs = new QTabWidget(this);
QWidget* vw = QWidget::createWindowContainer(m_quickWidget);
tabs->addTab(vw,"TAB Rendering");
tabs->addTab(new QWidget(),"TAB 1");
I have attached a qt project for emphasizing the problem
back trace for more info
Hi we have seen similar things including the black flickering, however 5.5 seems to have made that black flicker go away. Have you tried that?
Also, I would recommend that you post it on the Qt bug tracker so that someone from the Qt dev team can recreate and fix the problem.

White screen observed while launching the QGraphicsView application

Our application uses Qt's Graphics View framework to load the html pages. QGraphicsWebView loads local html page which is black background. But always observed the white screen while launching the application. I have tried setting black background for both QGraphicsView and QGraphicsScene. Nothing worked for me.
Here's the sample code for your reference.
MainWindow which inherited from QMainWindow class
mGraphicsScene = new QGraphicsScene(this);
mGraphicsView = new QGraphicsView(mGraphicsScene);
mGraphicsView->setViewport(new QGLWidget(this));
mGraphicsWebView = new QGraphicsWebView;
mGraphicsWebView->setUrl(QUrl("https://www.google.co.in/"));
mGraphicsScene->addItem(mGraphicsWebView);
setCentralWidget(mGraphicsView);
Is there any way to avoid white screen of the application?
Best Regards,
Pratap
Try next. Why did you see white? Because item already added, but page not loaded, so you see white(blank) item without page. Set to your scene some black pixmap, connect loadFinished signal to special slot, where you add item to your scene. In this case scene will be black, but when page will be loaded, your slot will add this on scnen and you will see only page.
mGraphicsScene = new QGraphicsScene(this);
mGraphicsScene->addItem(new QGraphicsPixmapItem(QPixmap("G:/2/qt.jpg")));
mGraphicsView = new QGraphicsView(mGraphicsScene);
mGraphicsView->setViewport(new QGLWidget(this));
mGraphicsWebView = new QGraphicsWebView;
mGraphicsWebView->setUrl(QUrl("https://www.google.co.in/"));
connect(mGraphicsWebView,SIGNAL(loadFinished(bool)),this,SLOT(slotLoaded()));
//mGraphicsScene->addItem(mGraphicsWebView);
mGraphicsView->resize(1000,700);
mGraphicsView->show();
Slot:
void MainWindow::slotLoaded()
{
mGraphicsScene->addItem(mGraphicsWebView);
}
For example black pixmap which was created by code:
QPixmap black(1000,700);
black.fill(Qt::black);
mGraphicsScene = new QGraphicsScene(this);
mGraphicsScene->addItem(new QGraphicsPixmapItem(black));
When application start:
As you can see, all is black, when page was loaded:
As you can see, it is normal page. It is not very beautiful because I use fast settings and resize window and so on, but you set graphicsview as central widget, do it will be more beautiful.
Thank you very much for the response.
I have tried your solution and also observed white screen while launching the application on Windows
I found the culprit is mGraphicsWebView->setUrl(QUrl("https://www.google.co.in/")); This is blocking all other widgets on the scene. So I have added a singleShot timer and kept this statement under that.
//QTimer::singleShot(100, this, SLOT(loadUrl())); Then it works fine.
Please let me know if you have any better idea.