I am trying to implement the displaying of a web page in Qt.I add one buttoon ,when clicked,update the new html content,and Re-execution the js,but when clicked 2 times,Popup execute 2 times,when clicked 3 times,Popup execute 3 times, I think, it add js to the html content many times. what should i do make the Popup execute 1 times?
[I want to clear previous html content when click the button.but i don't know how to do ]
in .h .
QWebEngineView *articleWebView;
in .cpp:
articleWebView = new QWebEngineView();
in js.
function abs() {alert("test");}
QString articleJS = readArticleJs ();
QString funcStr = QString("\n abs(\"%1 \",\"%2\");").arg(highlightWords1).arg(highlightSentece1);
articleJS.append (funcStr);
this->articleWebView->page ()->runJavaScript (articleJS);
Related
I'm using DX 15.1, and I'm trying to create a new tab from a child form.
So, basically, I have a parent form called "pForm", and a child form called "cForm".
I'm using DocumentManager module and switched it to TabbedView mode.
When I'm trying to create a new tab from pForm, it's totally fine.
the problem is, when I'm can't create a new tab from cForm into pForm's TabbedView.
How do I achieve this?
Thanks, mate :)
UPDATE :
#DmitryG, thanks for your response.
I've attached a screenshot below.
The MDI-Parent is the RGP page with a settings header. and the MDI-Child is the Class Attendance form (popped-up window, triggered by a button inside the RGP form).
Can you give a solution, how to make the Class Attendance Form (mdi-child) became a new Tab beside RGP tab when it's triggered by a button within mdi-parent? Not as a popped-up window.
thanks!
When the DocumentManager works in MDI Mode you can just work with mdi parent and child forms. So, I believe, you code for adding a new mdi-child into mdi-parent form can looks like this:
static void AddMdiChildFromMdiParent(Form mdiParent) {
Form child = new Form();
child.MdiParent = mdiParent;
child.Show();
}
Within the mdi-parent form you can call this code like this:
AddMdiChildFromMdiParent(this);
To add a new mdi-child from an existing mdi-child you can reuse the code above as follows:
static void AddMdiChildFromMdiChild(Form child) {
AddMdiChildFromMdiParent(child.MdiParent);
}
I'm trying to generate a dialog that contains an ad-on tool that is separate from my main program, it its triggered from an action within the menus.
I've got the following code:
void MainWindow::on_actionCalibration_Tool_triggered()
{
QGridLayout *grid = new QGridLayout;
NewDialog.setLayout(grid);
NewDialog.setMinimumHeight(500);
NewDialog.setMinimumWidth(800);
QLabel *label = new QLabel;
QFont sansFont("MS Shell Dlg 2",22, QFont::Bold);
label->setText("Test");
label->setFont(sansFont);
QPushButton *okbutton = new QPushButton;
QPushButton *closebutton = new QPushButton;
okbutton->setText("Ok");
closebutton->setText("Close");
QTimer *timer = new QTimer;
connect(okbutton,SIGNAL(clicked()),this,SLOT(on_ScanpB_clicked()));
connect(closebutton,SIGNAL(clicked()),this,SLOT(CloseDialog()));
grid->addWidget(label);
grid->addWidget(okbutton);
grid->addWidget(closebutton);
NewDialog.exec();
NewDialog.show();
}
void MainWindow::CloseDialog()
{
NewDialog.close();
}
With NewDialog being defined in main window.h as a QDialog.
My issue is when I click the close button, the dialog will close for a split second then reopen, after I click the close button for a second time it closes for good.
Is there any better implementation or way around this?
Thanks
You should not call QDialog::show and QDialog::exec. Instead, pick one to call.
Use exec if you want to block user interaction with the dialog's parent while the dialog is open. The user will not be play with anything else in the application until they dismiss the dialog. This is called a modal.
Use show if you want to allow the user to work with the dialog and the rest of the application at the same time.
Usually you'd choose exec. It is easier to work with. In your case, you displayed the dialog twice by calling both functions.
I am using windows form application to create gui. I have create a form with several button. The functionality of the first button called button1 is to read a video from hard disk and display it to a picturebox. The last line of button1 code is to enable another button:
button2->Enabled = true;
Button1 code is inside a backgroundworker. The result of this, it works fine, however it doesnt enable the button2. Is there issue using button properties inside backgroundworker?
You have to use BeginInvoke method and use Action delegate because backgroundworker DoWork doesn't modify UI.
private:
void DoWork(Object^ /*sender*/, EventArgs^ /*e*/ )
{
// some code
button2->BeginInvoke(gcnew Action(this, &MyForm::ModifyButton) );
}
void ModifyButton()
{
button2->Enabled = true;
}
In a QT application I am working on, we let the user pick a color using QColorDialog::getColor(). Based on an external event, I need to cancel this opened dialog. Is there a way to do it? I didn't see any other static method on QColorDialog to exit out of the dialog.
Or, may be a better method would be to close all opened dialogs. Is there such a method?
Following this Qt Forum post,
http://www.qtforum.org/article/37032/ok-cancel-buttons-on-qcolordialog.html
I tested the following code.
QColor color = QColorDialog::getColor();
if (!color.isValid()) return;
// Your process for selected color
// ...
and it properly worked for me.
Here is the code which you call by QColorDialog::getColor:
QColorDialog dlg(parent);
if (!title.isEmpty())
dlg.setWindowTitle(title);
dlg.setOptions(options);
dlg.setCurrentColor(initial);
dlg.exec();
return dlg.selectedColor();
As you can see it creates an instance of QColorDialog of stack, sets its initial properties, shows it and returns the result. You can use the same code to create the dialog BUT pay attention on how the dialog is shown.
Method QDialog::exec creates a new event loop (http://qt-project.org/doc/qt-4.8/qeventloop.html) and don't return until the dialog is closed.
That's why you can't call any method of QDialog. Thus QDialog::exec creates so called modal window (http://qt-project.org/doc/qt-4.8/qwidget.html#windowModality-prop).
Solution
To be able to interact with the dialog you need to create it using operator new and use method QDialog::show to show the dialog. But this method returns control immediately when the dialog is shown. So you won't be able to get the color in the next line of your code. Instead you need to subscribe to the dialog signals accepted and rejected, process the results (dialog->currentColor()) and delete the dialog object.
Also you've asked about a way to close all opened dialog. Supposing that all you dialogs are inherited from QDialog:
foreach (QWidget *widget, QApplication::topLevelWidgets()) {
if (QDialog* dialog = qobject_cast<QDialog*>(widget))
dialog->close();
}
This works for me:
QColorDialog *dialog = new QColorDialog(this);
dialog->show();
QObject::connect(dialog,&QDialog::accepted,[=](){
QColor color = dialog->currentColor();
QVariant variant = color;
QString rgb= variant.toString();
ui->eg->setStyleSheet("QLabel { color :"+rgb+" ; }");});`
I hope It helps someone! The above works to change the QLabel font and/or frame but u can try different stylesheets i.e
ui->label->setStyleSheet("QLabel { background-color :"+rgb+" ; color : white; }");
You can not do this when using the static getColor() function.
Construct a dialog object instead so you get a pointer allowing you to call all available functions (like reject() or close()).
EDIT:
okay, i have checked the code and its rendering out by a jquery widget.
END
I am trying to move the cursor to <a \>, but the problem is that the element is not rendered until i move mouse pointer physically on selected image.
How can i move to the mouse to hover over <a \> to select/click?
FF version 20
Selenium WebDriver version: 2.31.2.0
Current code
Actions actions = new Actions(driver);
int locationX = Convert.ToInt32(ratingElementDiv[i].Location.X);
int locationY = ratingElementDiv[i].Location.Y;
actions.MoveToElement(WaitForElement(By.CssSelector(starElement)), locationX, locationY).Click().Perform();
i dont see any action happening... any help?
Action is composed by 3 steps.
configuration
Actions builder = new Actions(driver);
Point location ratingElementDiv[i].getLocation();
builder.MoveToElement(WaitForElement(By.CssSelector(starElement)), location.X, location.Y).click();
(i'm not sure about the click)
get the action
Action selectLink = builder.build();
execution
selectLink.perform();
try this and tell me if you still have some problem.
This link will help you. It explain both keyboard and mouse event.
http://www.guru99.com/keyboard-mouse-events-files-webdriver.html
Lets say when you click "Select Your Test" you see a dropdown of multiple elements(ABC, DEF, GHI, etc ). You want to select ABC and click it. Use following.
driver.findElement(By.linkText("Select Your Test")).click();
new Actions(driver).moveToElement(driver.findElement(By.linkText("ABC"))).click().perform();
it works to me
//定位一個按鈕
WebElement button = driver.findElement(By.xpath("//div[#class='page-button']"));
//new 一個移動滑鼠的物件
Actions clickAction = new Actions(driver).click(button);
//執行
clickAction.build().perform();